-->
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: mapping 2 db tables to single java class?
PostPosted: Mon Feb 04, 2008 2:19 am 
Newbie

Joined: Mon Feb 04, 2008 1:53 am
Posts: 1
Location: SF Bay Area, CA
Hi All,
I am very new to hibernate and currently trying to find the solution (if it is exist) for the following problem.
I have 2 db tables (mySql)
Customer table
id (int 11, not null, primary, increment)
customer_id (varchar 32, not null, unique)
first_name(varchar 32)
last_name (varchar 32)
email (varchar 32, not null, unique)
password (varchar 80, not null)
account_creation_date (timestamp, not null)

artist table
id (int 11, not null, primary, incremental)
account_id (varchar 32, not null, unique)
customer_id (varchar 32, not null, unique)

where artist.customer_id is the same value as customer.customer_id

I am trying to have only one class Customer where I can map both tables (customer and artist).
My question how can I do that, having only Customer.java and Customer.hbm.xml without declaring Artist.java and Artist.hbm.xm

I tried...

<hibernate-mapping>
<class name="org.testbox.crm.model.Customer" table="CUSTOMERS">
<id name="c_id" column="id" type="long">
<generator class="native"/>
</id>

<property name="customerId"
column="customer_id"
not-null="true"
update="false"
insert="true"
unique="true"
type="string"/>

<property name="firstName"
column="first_name"
type="string"/>

<property name="lastName"
column="last_name"
not-null="true"
type="string"/>

<property name="email"
column="email"
not-null="true"
type="string"/>
<property name="password"
column="password"
not-null="true"
type="string"/>

<property name="accountCreationDate"
column="account_creation_date"
not-null="true"
insert="true"
update="false"/>

<set name="artistId" table="ARTIST"
lazy="true"
inverse="true"
cascade="all">
<key column="customer_id"/>
<element type="string" column="artist_id"/>
</set>

</class>
</hibernate-mapping>

and declared
private Set<String> artistId;
in Customer.java

but when I do

Customer newCust = new Customer();
newCust.setCustomerId(UtilHelper.getUUID());
newCust.setEmail("qas@testbox.org");
newCust.setFirstName("qa");
newCust.setLastName("tester");
newCust.setPassword("1234567");
newCust.setAccountCreationDate(UtilHelper.getTodaydate());
Set<String> artSet = Collections.synchronizedSet(new HashSet<String>());
artSet.add(UtilHelper.getUUID());
newCust.setArtistId(artSet);

driver.getDao().save(newCust);

this code creates new customer, but never updates the Artist DB table
I am using Windows XP, Java 5 and hibernate3.2.5

Please if somebody could help me out figure this solution.
Thank you in advance,

Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 7:37 am 
Newbie

Joined: Mon Feb 04, 2008 7:29 am
Posts: 7
Location: Belarus
You should use entity-name attribute in your schema and the different API for this. Look at http://forum.hibernate.org/viewtopic.php?t=983298

P.S.: also look in "Java persistence with Hibernate" - section 3.4.1 "Creating dynamic applications - Mapping a class several times".


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.