Added by on 2013-07-05

1. Customer class

@Entity
@Table(name="Customer")
@SecondaryTable(name="CustomerDetails")
public class Customer{

	@Id
	@GeneratedValue
	private int customerId;
	private String customerName;

	//customerAddress should go to CustomerDetails table
	@Column(table="CustomerDetails")
	private String customerAddress;

	//creditScore should go to CustomerDetails table
	@Column(table="CustomerDetails")
	private int creditScore;

	//rewardPoints should go to CustomerDetails table
	@Column(table="CustomerDetails")
	private int rewardPoints;

}

2. TestCustomer class

public class TestEmployee{
	public static void main(){
		AnnotationConfiguration conf = new AnnotationConfiguration5-,
		conf.addAnnotatedClass(Employee.class);
		new SchemaExport(conf).create(true, true);

		SessionFactory factory = conf.buildSessionFactory();
		Session session = factory.getCurrentSession();
		session.beginTransaction();

		Customer c = new Customer();
		c.setCustomerName("Customer name");
		c.setCustomerAddress("an adr");
		c.setCreditScore(15);
		c.setRewardPoints(18);

		c.set
	}
}

3. The 2 created tables will be:

  • Customer(customerId, customerName);
  • CustomerDetails(#customerId, customerAddress, creditScore, rewardPoints);

Category:

Hibernate

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*