Skip to main content

problem with relationships and "Query sent to a unactivated UnitOfWork."

3 replies [Last post]
lynggaard
Offline
Joined: 2003-06-14
Points: 0

Hi

I am trying to learn EJB3 and is developing a small bookmark app. However I am having a problem..

I have two entities:
Bookmark:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;
private String url;
private Timestamp accessTime;
@ManyToMany()
@OrderBy("name")
private Collection tags;

Tag:
@Id
@GeneratedValue()
private Long id;
private String name;
private String description;

@ManyToMany(mappedBy="tags")
@OrderBy("accessTime")
private Collection bookmarks;

And in a Stateless Session bean facade I have the following code:

public Collection getBookmarkForTag(String tagId)
{
Tag currentTag = tagFacade.getTag(tagId);
return currentTag.getBookmarks();
}

The TagFacade.getTag does a finder based on the id after it has been converted to a long.

This code works when I just deploy the application form netbeans, but if I then restart the glassfish server I get the following exception:

Exception [TOPLINK-6027] (Oracle TopLink Essentials - 10g release 4 (10.1.4.0.0) (Build 060301Dev)): oracle.toplink.essentials.exceptions.QueryException
Exception Description: Query sent to a unactivated UnitOfWork.
Query: ReadAllQuery(org.lynggaard.rememberplaces.datamodel.Bookmark)
oracle.toplink.essentials.exceptions.QueryException.querySentToInactiveUnitOfWork(QueryException.java:892)
oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2193)
oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
oracle.toplink.essentials.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:83)
oracle.toplink.essentials.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:76)
oracle.toplink.essentials.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:82)
oracle.toplink.essentials.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:160)
oracle.toplink.essentials.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:229)
oracle.toplink.essentials.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:82)
oracle.toplink.essentials.indirection.IndirectList.buildDelegate(IndirectList.java:193)
oracle.toplink.essentials.indirection.IndirectList.getDelegate(IndirectList.java:315)
oracle.toplink.essentials.indirection.IndirectList.size(IndirectList.java:640)
org.lynggaard.rememberplaces.frontend.Main.processRequest(Main.java:49)

Anyone know why ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stvconsultants
Offline
Joined: 2006-03-06
Points: 0

Maybe this is a doh! answer:

When you restart the glassfish server outside of netbeans, are you ensuring that the database is started as well? Netbeans can be really helpful and I have seen it start my Derby database automagically, but if you start glassfish with
asadmin start-domain domain1
you'll have to ensure that the database is started too with
asadmin start-database
Of course you'll need to watch out for the gotcha where glassfish uses a different instance of derby from netbeans and so your tables may not be created!

Maybe this is a pointer to the problem:
I have gotten these types of exceptions and had them go away (only to be replaced with a different set of NPEs) by changing the fetchType to FetchType.LAZY

lynggaard
Offline
Joined: 2003-06-14
Points: 0

Thanx for the reply, I have just verified your suggestions just to be on the safe side.

The database is started, in fact I start both from outside netbeans even when I deploy from netbeans.

Netbeans sometimes has troubles starting glassfish on my machine, it just appears to hang.

The database instance is the same as I can see the frontpage and it loads fine along witht the data.

The frontpage shows all "tags" and all "bookmarks", but when I click on a tag to only show bookmarks for said tag I get the error. I think it happends when I navigate the relationship

chris_delahunt
Offline
Joined: 2005-07-06
Points: 0

Hello,

Not sure how you are getting the object you are calling size() on. The exception seems to indicate though that you have lazy loaded relationships, and that you are trying to access one after the context used to read it in has closed.

Hope this helps,
Chris