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
|