-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Two classes mapping to same Table.
PostPosted: Thu Feb 05, 2009 7:28 pm 
Newbie

Joined: Sun Oct 12, 2008 2:06 am
Posts: 3
Is it possible to map two classes to the same table? For example:

I have a table EMPLOYEE with columns: id, name, address1, address2, city, state, employername, employeraddress, salary

What I did was: I made two mapping files: employee.hbm.xml and address.hbm.xml.

employee.hbm.xml maps to EMPLOYEE table with id, name, employername, employeraddress, salary (class name: Employee)

address.hbm.xml maps to EMPLOYEE table with id, address1, address2, city, state (class name: Address)

and employee.hbm.xml has one-to-one reference to Address class.

Please let me know if the concept is technically correct. I was getting a Null Pointer exception while query ( 'select e from Employee e') ( I do not have the exact error right away because I changed my design to avoid this situation)

Null Pointer Exc
org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1645)

Please help me understand what wrong I am doing.


Thanks


Top
 Profile  
 
 Post subject: Re: Two classes mapping to same Table.
PostPosted: Thu Feb 05, 2009 11:28 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Hi,

Is there any special reason for not to separate your EMPLOYEE table as EMPLOYEE and EMPLOYEE_DETAILS?

If you can do you can define Employee and Address class and relate them to each other, or second option you can have just Employee table and use @SecondaryTable annotation in order to map Employee class to the those tables.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.