-->
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.  [ 3 posts ] 
Author Message
 Post subject: Different mappings for reading and writing same object
PostPosted: Thu Feb 09, 2006 4:23 pm 
Newbie

Joined: Thu Feb 09, 2006 3:34 pm
Posts: 2
We need to create an object from data in 2 different tables. We are using a join tag and this works correctly.

However, we would like to be able to write some of the attributes from the object back to only one of the tables, since only one of the tables contains dynamic data. We were trying to do this using 2 different mappings using entity-names in the class tags to distinguish between them (one "read" and one "write"). The second mapping (write) works just fine using the entity-name, but now the first mapping (read) with the join, gives us an error when we try to reference it by entity-name:

class [entity-name] not found while looking for property: [first property name inside join tag]

Our read mapping looks something (loosely) like this:

<class name="Blah" table="Static_Table" entity-name="Read">

<property name="Id" update="false" insert="false">
<column name="MsgID" sql-type="string" not-null="true" />
</property>

<property name=...

<join table="Dyna_Table">
<key>
<column name="ID" not-null="true" />
</key>

<property name="clientID" >
<column name="CLIENT_ID" sql-type="int" not-null="true" />
</property>

<property name=...

</join>

</class>

Can anybody tell us what the problem is?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 4:54 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
For the read property, use the <formula> element instead of the <column> element. <formula>columnname</formula> will read from columnname but never write to anything. Note that columnname is not parsed by hibernate, so you put the DB column name, not the hibernate property name, in there.


Top
 Profile  
 
 Post subject: Different mappings for reading and writing same object
PostPosted: Thu Feb 09, 2006 8:15 pm 
Newbie

Joined: Thu Feb 09, 2006 3:34 pm
Posts: 2
There is a problem with using a single mapping (no entity-names) solution to read and write data back to the database, even using the formula tag for the columns/table we don't want to write back. The key that is specified inside of our join tag is the foreign key to the static data table we are joining with, not the primary key to the dynamic table to which we want to write. So when Hibernate constructs the SQL to update the dynamic data table, it is using the wrong key.

What we were trying to do was use two mappings - one to read, and one to write using the entity-name to distinguish between them. The read mapping works just fine without the entity-name, but not with it, apparently because of the join. The write mapping works fine for reading and writing, but it would only read data from one table and we need data from two. Our object is composed of data from two tables, but we will only ever want to update one of the two tables.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.