-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem refering foreign key directly...
PostPosted: Fri Feb 17, 2006 9:38 am 
Beginner
Beginner

Joined: Sun Oct 16, 2005 12:37 pm
Posts: 47
Location: Romania, Galati
Hello,

I have a situation. I have a mapping (ex.: documents.hbm.xml) with a lot of many-to-one mapping (one of them is for example inventory). The problem is that I have many of them as a id (ex.: InventoryId) from session (ex.:MySession.getInventoryId()). I knew that inventory for specified id already exists, so instead of obtaining the instance of Inventory for that id I wanna set Id directly.

Brief ex.:

Now I have

Session ses = sf.openSession();
Transaction tx = ses.beginTransaction();
Integer invId = MySession.getInventoryId();

Documents doc = new Documents();
Inventory inv = (Inventory)ses.createCriteria(Inventory.class).add(Restrictions.eq("Id", invId)).uniqueResult();
doc.setInventory(inv);

ses.saveOrUpdate(doc);
tx.commit();
ses.close();

And I wanna put:

doc.setInventory(invId);

instead of bold statements.

I tried put another property in Documents.hbm.xml named inventoryId that map the same column InventoryId but Hibernate forced me to put
update="false" and insert="false" :(

thx.

Hibernate version:3.0.5.

Mapping documents:documents.hbm.xml, Inventory.hbm.xml

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:None

Name and version of the database you are using:MySQL-4.1.7

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


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

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.