-->
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.  [ 5 posts ] 
Author Message
 Post subject: What is the right way to initialize the lazy field
PostPosted: Fri Feb 10, 2006 9:23 am 
Newbie

Joined: Thu Oct 20, 2005 4:15 am
Posts: 8
Hibernate version:
3.1.2
EntityManager beta 6
Annotation beta 8

Name and version of the database you are using:
MS SQL

I have Operation Entity with field of type algorithm declared as follows:
@OneToOne(targetEntity = Algorithm.class, cascade = CascadeType.ALL,
fetch = FetchType.LAZY)
@org.hibernate.annotations.Cascade(
org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name = "oper_id")
public IAlgorithm getAlgorithm() {
return algorithm;
}


what is the right way to initialize algorithm in the entityManager other than the one I've loaded operation with.

The poing is that when i use query like:
Query q = em.createQuery(
"select op.algorithm from Operation op where op.id = ?1");
q.setParameter(1, operation.getId());
operation.setAlgorithm((IAlgorithm) q.getSingleResult());

the SECOND time i save operation none of algorithm children are saved using em.merge() command :(

Good luck and thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 10:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You've never run this code
Code:
Query q = em.createQuery(
"select op.algorithm from Operation op where op.id = ?1");
q.setParameter(1, operation.getId());
operation.setAlgorithm((IAlgorithm) q.getSingleResult());


it shold raie a ClassCastException

_________________
Emmanuel


Top
 Profile  
 
 Post subject: new information
PostPosted: Mon Feb 13, 2006 6:41 am 
Newbie

Joined: Thu Oct 20, 2005 4:15 am
Posts: 8
Thank you, emmanuel for your attention, i see that you are working much on helping people at this forum.

Actually that code runs without exceptions. Before posting my question here i was working on this issue for something like 3 days. So could you please point out where exactly, do you think, that should be ClastCastException, and why?

By the way, we are experiencing kind of black magic here.
The domain model is like:
Operation 1-1 Algorithm 1-n Procedure 1-1 ProcedureText 1-n ProcedureTextBlock... and so on.

I would like to have Operation-Algorithm and Procedure-ProcedureText to be LAZY. Because of problems described in first post to this topic, I've turned LAZY to EAGER for both assocciations mentioned. TestCases went fine. THEN i've turned Operation-Algorithm back to LAZY and TestCases went fine also, BUT in our application we started to get LazyInitException at the algorithm.getProcedures() witch have allways been an EAGER assocciation! :)

You can find my domain model here :http://www.bekarsoft.com/mikler/domain.rar

what ever...
i would like you to answer to question, witch i can not find in docs, FAQs or anywhere else. The question is
WHAT IS THE RIGHT WAY TO INITIALIZE LAZY PROPERTY, WITCH WAS LOADED IN ANOTHER ENTITYMANAGER?


Top
 Profile  
 
 Post subject: problem seems to be found
PostPosted: Mon Feb 13, 2006 9:32 am 
Newbie

Joined: Thu Oct 20, 2005 4:15 am
Posts: 8
problem seems to be found


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 10:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
oh I misread your query. I didn't see the select op.algorithm

_________________
Emmanuel


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