How to privent population of same data in DataBase with Hibernate - database

I'm doing my own project and have something to store in mysql database.
After thinking what should be a best solution DO NOT repeat same value's in DataBase again I didn't find an answer.
So let's example,
Table Cars with rows Cars_ID and Cars_VALUE
-=JoinTable between Cars and Cars_CreationDate=-
Table Cars_CreationDate with rows Cars_CreationDate_ID and Cars_CreationDate_VALUE
-=JoinTable between Cars_CreationDate and Cars_Description=-
Table Cars_Description with rows Cars_Description_ID and Cars_Description_VALUE
In hibernate entities I would have relationships like this:
Between Entity Cars_CreationDate and Cars #ManyToMany, owner of relationships is Cars_CreationDate. Because many Cars can be made in one date and one date can have many cars.
Between Entity Cars_Description and Cars #ManyToOne, owner of relationships is Cars entity, entity Cars_Description belongs to Cars. Entity Cars_Description everytime extracts from database with Cars. fetchType=EAGER
Now let's see if we have in DataBase some Cars made already and I want to add new date to this cars I would say:
Cars cars = (Cars)session.get(Cars.class, int idindatabase); // If we do this for a couple times more for different Cars we will have THE SAME Cars_Description_VALUE corresponds to different Cars so it would looks like this
2013-07-03 to CarOne
2013-07-03 to CarTwo
2013-07-03 to CarTree
and etc. So I don't need this dates repeat every time.
How do not let this problem to be??? Thank you

I don't see much value in using a separate entity/table to store a single value to avoid having to write them out - either a car has a date or a car has a reference to a date. I'd put the date in Car and be done with it. But in theory, what you want is a foreign key in Car to reference your Date. Each car will have a date ID that is used to find the date row/entity. Your date objects then can have a 1:M relationship back, so they can have a collection of cars.
in CarEntity:
#ManyToOne
#JoinColumn(name="CREATIONDATE_ID"
DateEntity creationDate;
In DateEntity:
#OneToMany(mappedby="creationDate")
Collection<CarEntity> cars;

Related

Quick Books Data Layout in DB in SQL Server

I am new to QuickBooks. I am working on a staging SQL Server 2017 (v14) for grocery store data.
The QuickBook data was uploaded to server.And many tables are empty.
The datalayout is as in: https://doc.qodbc.com/qodbc/usa
I am looking to understand the data structure, to be able find the Purchasing Amount of Inventory, grouped by department per week.
The data is grocery store data. The QB has Payroll data tables. I am able to make sense of this payroll data.
But unable to find Purchasing Data- I do not see how the items can be grouped (class?) and where is the DateField (TxnDate?) and how do I summarize for a week.
There are some reports on QuickBooks that can brought into Excel; should I use that? Any pointers on which one?
I am not able to understand the column names ListIDs (a lot of this - may be descriptors) and Txn ID and TxnlineID.
Any pointers on how to understand how the inventory purchasing data is filed and kept in QBs- will help a lot.
https://support.flexquarters.com/esupport/index.php?/Knowledgebase/Article/View/2369/0/how-to-use-the-quickbooks-reporting-engine-with-qodbc
QuickBooks has two types of data, Lists and Transactions (Txn). The ListID is the primary key for the list table, and the TxnID is the primary key for transaction tables. If a transaction has line items (like a Bill) each line has it's own TxnLineID.
Inventory can be purchased (or returned) through four transactions: Bill, Check, CreditCardCharge, or VendorCredit (for returning inventory to vendor).
The Bill/Check/CC/VC tables will also have their corresponding LineItem tables, as these transactions can have more than one item purchased at a time. These will have the ItemLine after the parent table name, i.e. BillItemLine. Each of these lines will have a Item reference back to the ItemList table to know what item was purchased. The IDs that QuickBooks uses is (like 4651C-1355327815) is it's own internal generated ID, but it functions just like a primary key, and the other tables that have references (like ItemLineItemRefListID) are the Foreign Key to the other tables.
https://doc.qodbc.com/qodbc/usa/TableList.php?categoryName=Purchases shows all the purchasing transactions, but you only need to look at the ones that have ItemLines. Other purchasing transactions, like PurchaseOrders do NOT effect inventory quantities in QuickBooks. Only Bill, Check, CreditCardCharge, and VendorCredit have an effect.

creating a database for houses (SQLite3)

got a python sqlite3 spider crawling through a website and essentially got an address, and the dates that it was sold for along with the corresponding prices it was sold for. The first database is for address, postcode, number of bedrooms and second is points in time it was sold I am thinking of arranging the second database that has prices like so :
(Unique_id, date_1, sale_price_1, date_2, sale_price_2...etc..etc)
but this does not seem very efficient, for example, I may put down five date and sale columns but the crawler may come across a house sold seven times... is there a more efficient way to organise the second database of sold prices?
thank you in advance
I would create two tables: one for houses, and one for transactions and link them via a foreign key.
Each house will only have one row in the houses table, but may have any number of rows in the transactions table.
The transactions table will have a foreign key to the house that was sold, along with columns about the sale, such as date and sale price.

how to design person table for a movie database

there is a problem of designing a movie database. A movie can only have one director and many actors and many writers, also the actors should be stored in a CAST table which shows the role of each actor in the movie and the STAR ACTOR should be identified.
how should i implement this? any help
here is the ERD
I would have a separate table for each of writer, director, and actor. It seems as though the data you'd like to store for actors (i.e. "Star Actor") wouldn't ever apply to a director or a writer.
OR
Make an actors table, and a separate "crew" table, which could include both directors and writers. A column in the crew table could be "profession" or something like that, which would be a foreign key to a "profession" table.
So I'd say that at minimum you'd want a separate table for the actors.

Multiple tables access database

I am very new to Access and I am working on a database and I need help coming up with a solution:
I am recording data from a bunch of asphalt laying crews. Each crew has a record with a field for production and equipment. Each crew has varying types of equipment and varying quantities of equipment. Therefore, I would need to create a new table for the type and quantity of equipment every time I enter a new record... can someone please help me come up with a solution?
You do not need a new table for each record, you just need a properly set up table. Let us say:
Crews table
CrewID
Location
Etc
CrewMembers table
MemberID
Etc
CrewEquipment table
CrewID
EquipmentID
DateIn
DateOut
Etc
Equipment table
EquipmentID
Details
Etc
You might like to read http://r937.com/relational.html
With the above set-up, you can have a Crew form with subforms for members and equipment. You can get an idea from this create form to add records in multiple tables
Creating new table everytime is not solution, you should clear some RDBMS concept like normalization first. Create separate table for
crew member (which include crew member id, his name, salary/wages
List item per hour) equipments (which include equipments id, operation cost per hour etc)
Shift (can be separated by date and shift time etc)
Then create proper relationship between tables and this way you can create proper relational database system. so finish some basic tutorial first then start development.

Database design query

I've designed a database structure where data is collected about cars over a period of time, for research purposes. The owner of the car enters a large amount of related data each month about the car, it's performance etc. However, I now have to handle situations where ownership of the car is transferred (possibly more than once), and I'm wondering what the best way to handle this in the database would be.
If a car is transferred, the previous owner should no longer be able to add data about the car, however they should still be able to view the data they entered up until the date of the transfer. The new owner will be able to enter data about the car from the date of the transfer onwards. For research purposes, I need to be able to join the data between these transferred car records and consolidate them into one set of data.
Currently, each car record in the db belongs to an owner via a foreign key in the Cars table. What I'm thinking about at the moment, is to create a recursive parent/child relationship between car records, where one car record may belong to another car record (e.g car_id as a foreign key in Car table). Where a car record belongs to another car record, this indicates a transfer. This allows me to preserve each car record's set of data (specific to its owner), while also chaining together the related car records. In addition to this, I'm thinking about adding a Car_transfer table, to record extra data about the transfer (probably just the date actually, as the previous and new owners will be evident from the owner_ids in the Car table) - adding a date_transferred column in the Car record would likely be largely redundant for most records, so i'm unsure if this data alone merits a new relationship table.
Anyway, i hope this makes sense! I've been going round in circles trying to find a sensible solution - any advice would be greatly appreciated!
You don't need recursive parent/child here, but just Many-To-Many relationship:
Basically you need links table [cars-owners]:
car_id, owner_id, ownership_date
So you will have data in it:
---------------
1, 2, 2009-01-01
1, 3, 2010-05-01
...
The same car owned by two people with different dates.
I would add a car ownership table. The recursive design isn't too intuitive.

Resources