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:
|
|