Skip to main content

Posts

Showing posts with the label Hibernate

Databases - Basics

In the previous post ( Databases Introduction )  we looked at different types of databases and simple concepts of tables. In this section, we will look at some basics of databases- tables, inner joins and outer joins. The syntax of SQL used here is for Oracle. However, it is very similar in all other databases such as MySQL, MS SQLServer, Postgres, etc.. Tables We will create two tables by using the SQL statements below:   create table customer (cust_id number(4,0) not null, customer_name varchar2(60) not null); create table invoice (invoice_id number(4) not null, cust_id number(4) not null , invoice_total number(10,2) default 0.00, paid_ind char(1)); In the first SQL we create the table called Customer with the column names cust_id and customer_name. Observe that we do not want to store null values in each of the columns in the customer table. In the second SQL we create the table invoice, which has its columns and also the cust_id column from the customer ...

Hibernate-Secondary Table Annotation..

When using Hibernate with annotation, SecondaryTable needs to be used carefully while using the Discriminator. We assume that there is a table called Inventory which is the parent table that has common elements including Id, createDate, modifiedDate, SKU#, and productType. The other tables, which are children of the Inventory table, are TV_Inventory, DVD_inventory etc.. In this example, we consider TV_Inventory which inherits from Inventory (in terms of objects). @Entity @Table(name = "INVENTORY") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "PRODUCT_TYPE", discriminatorType = DiscriminatorType.STRING, length = 20) @SequenceGenerator(name = "InventorySequence", sequenceName = "INV_SEQ", allocationSize = 1) public abstract class Inventory {  // getters and setters with other annotations for the columns and relevant methods. }   Consider the child object associated with the table TV_INVENTORY. The outli...