JPA error

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

JPA error

measwel
LS,

I am having trouble understanding how to synchronize my object model with the DB. I have a User entity that has a collection of Favorite entities. When I insert or delete a favorite in the DB (using JPA on the Favorite object), I would expect this change to be automatically reflected in the User's Favorite collection (this is mapped by a @oneToMany annotation) when I access the collection. Unfortunately, it seems JPA does not do this; I have to update the collection by hand.

So I do. I add or remove the Favorite from the collection. In subsequent code, I read from the User's Favorites collection in order to detect adding a duplicate Favorite. A new Favorite has a MovieID property and if any Favorite in the collection has the same MovieID, then the new favorite should not be added in order to prevent duplicates.

Now the trouble starts. If I do the MovieID comparison shortly after updating the collection or shortly after starting the webbapplication, it goes okay. But, if some time passes between updating the collection (adding / removing a favorite) and comparing a new favorite's MovieID to the ones in the collection, the comparison fails. It fails even though I can trace in debug mode, that a favorite with the same MovieID is in the User's favorites collection! And it returns the ID correctly. The code is:

  public boolean movieIsFavorite(Wuser user, Movie movie) {
//    Iterator it = jpaController.findByUser(maxResults, firstResult, user).iterator();
    Iterator it = user.getFavorites().listIterator();
    while (it.hasNext()) {
      Favorite uf = (Favorite) it.next();
      if (uf.getMovie().getMovieID() == movie.getMovieID()) {
        return true;
      }
    }
    return false;
  }

In the commented out line, I want to read directly from the DB by using the Favorite's JPA controller and filtering on the current user. This should go well (have not tried it yet), but why does it fail when I use the user's favorites collection?

So the comparison returns false, even though a favorite with the same movieID is in the collection. On the subsequent page I show the user's favorites - again reading from the collection, not via the favorite's JPA controller - and this produces the following error:

javax.el.ELException: Exception [EclipseLink-6004] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.QueryException
Exception Description: The object [jpa.entities.Movie[movieID=1007056]], of class [class jpa.entities.Movie], with identity hashcode (System.identityHashCode()) [6 117 163],
is not from this UnitOfWork object space, but the parent session's.  The object was never registered in this UnitOfWork,
but read from the parent session and related to an object registered in the UnitOfWork.  Ensure that you are correctly
registering your objects.  If you are still having problems, you can use the UnitOfWork.validateObjectSpace() method to
help debug where the error occurred.  For more information, see the manual or FAQ.

Could somebody please tell me what the heck is going on? How can I make sure my model and the DB stay synchronized and how can I make sure, that the objects I access in memory have valid data structures that behave normally, like you would expect them too?

Or do I always need to make a roundtrip to the DB if accessing a persisted object's data? That can not be the point of a persistence architecture, can it?

Thank You all in advance for the help,
Marek

Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Grover Blue
My comments are inline below.

On Sat, Aug 22, 2009 at 7:15 AM, measwel <[hidden email]> wrote:

LS,

I am having trouble understanding how to synchronize my object model with
the DB. I have a User entity that has a collection of Favorite entities.
When I insert or delete a favorite in the DB (using JPA on the Favorite
object), I would expect this change to be automatically reflected in the
User's Favorite collection (this is mapped by a @oneToMany annotation) when
I access the collection. Unfortunately, it seems JPA does not do this; I
have to update the collection by hand.


So I do. I add or remove the Favorite from the collection. In subsequent
code, I read from the User's Favorites collection in order to detect adding
a duplicate Favorite. A new Favorite has a MovieID property and if any
Favorite in the collection has the same MovieID, then the new favorite
should not be added in order to prevent duplicates.

Now the trouble starts. If I do the MovieID comparison shortly after
updating the collection or shortly after starting the webbapplication, it
goes okay. But, if some time passes between updating the collection (adding
/ removing a favorite) and comparing a new favorite's MovieID to the ones in
the collection, the comparison fails. It fails even though I can trace in
debug mode, that a favorite with the same MovieID is in the User's favorites
collection! And it returns the ID correctly. The code is:

 public boolean movieIsFavorite(Wuser user, Movie movie) {
//    Iterator it = jpaController.findByUser(maxResults, firstResult,
user).iterator();
   Iterator it = user.getFavorites().listIterator();
   while (it.hasNext()) {
     Favorite uf = (Favorite) it.next();
     if (uf.getMovie().getMovieID() == movie.getMovieID()) {


Try: if (uf.getMovie().getMovieID().equals(movie.getMovieID())){

 

       return true;
     }
   }
   return false;
 }

In the commented out line, I want to read directly from the DB by using the
Favorite's JPA controller and filtering on the current user. This should go
well (have not tried it yet), but why does it fail when I use the user's
favorites collection?

So the comparison returns false, even though a favorite with the same
movieID is in the collection. On the subsequent page I show the user's
favorites - again reading from the collection, not via the favorite's JPA
controller - and this produces the following error:

javax.el.ELException: Exception [EclipseLink-6004] (Eclipse Persistence
Services - 1.0.1 (Build 20080905)):
org.eclipse.persistence.exceptions.QueryException
Exception Description: The object [jpa.entities.Movie[movieID=1007056]], of
class [class jpa.entities.Movie], with identity hashcode
(System.identityHashCode()) [6 117 163],
is not from this UnitOfWork object space, but the parent session's.  The
object was never registered in this UnitOfWork,
but read from the parent session and related to an object registered in the
UnitOfWork.  Ensure that you are correctly
registering your objects.  If you are still having problems, you can use the
UnitOfWork.validateObjectSpace() method to
help debug where the error occurred.  For more information, see the manual
or FAQ.

Could somebody please tell me what the heck is going on? How can I make sure
my model and the DB stay synchronized and how can I make sure, that the
objects I access in memory have valid data structures that behave normally,
like you would expect them too?

Or do I always need to make a roundtrip to the DB if accessing a persisted
object's data? That can not be the point of a persistence architecture, can
it?

Thank You all in advance for the help,
Marek




--
“If the American people ever allow private banks to control the issue of their currency, first by inflation, then by deflation, the banks...will deprive the people of all property until their children wake-up homeless on the continent their fathers conquered... The issuing power should be taken from the banks and restored to the people, to whom it properly belongs."   -- Thomas Jefferson


www.CampaignForLiberty.org
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
In reply to this post by measwel
What is the datatype of returned by getMovieID(). If it's a non primitive (like a Long or Integer instead of the primitive long or integer) then the comparison with == is an identity check, which won't work as expected. Columns from the database, even though from the same row doesn't always have the same identity, even though this would have been nice.

You need to use .equals() to check for equality.

Q

On Sat, Aug 22, 2009 at 1:15 PM, measwel <[hidden email]> wrote:

LS,

I am having trouble understanding how to synchronize my object model with
the DB. I have a User entity that has a collection of Favorite entities.
When I insert or delete a favorite in the DB (using JPA on the Favorite
object), I would expect this change to be automatically reflected in the
User's Favorite collection (this is mapped by a @oneToMany annotation) when
I access the collection. Unfortunately, it seems JPA does not do this; I
have to update the collection by hand.

So I do. I add or remove the Favorite from the collection. In subsequent
code, I read from the User's Favorites collection in order to detect adding
a duplicate Favorite. A new Favorite has a MovieID property and if any
Favorite in the collection has the same MovieID, then the new favorite
should not be added in order to prevent duplicates.

Now the trouble starts. If I do the MovieID comparison shortly after
updating the collection or shortly after starting the webbapplication, it
goes okay. But, if some time passes between updating the collection (adding
/ removing a favorite) and comparing a new favorite's MovieID to the ones in
the collection, the comparison fails. It fails even though I can trace in
debug mode, that a favorite with the same MovieID is in the User's favorites
collection! And it returns the ID correctly. The code is:

 public boolean movieIsFavorite(Wuser user, Movie movie) {
//    Iterator it = jpaController.findByUser(maxResults, firstResult,
user).iterator();
   Iterator it = user.getFavorites().listIterator();
   while (it.hasNext()) {
     Favorite uf = (Favorite) it.next();
     if (uf.getMovie().getMovieID() == movie.getMovieID()) {
       return true;
     }
   }
   return false;
 }

In the commented out line, I want to read directly from the DB by using the
Favorite's JPA controller and filtering on the current user. This should go
well (have not tried it yet), but why does it fail when I use the user's
favorites collection?

So the comparison returns false, even though a favorite with the same
movieID is in the collection. On the subsequent page I show the user's
favorites - again reading from the collection, not via the favorite's JPA
controller - and this produces the following error:

javax.el.ELException: Exception [EclipseLink-6004] (Eclipse Persistence
Services - 1.0.1 (Build 20080905)):
org.eclipse.persistence.exceptions.QueryException
Exception Description: The object [jpa.entities.Movie[movieID=1007056]], of
class [class jpa.entities.Movie], with identity hashcode
(System.identityHashCode()) [6 117 163],
is not from this UnitOfWork object space, but the parent session's.  The
object was never registered in this UnitOfWork,
but read from the parent session and related to an object registered in the
UnitOfWork.  Ensure that you are correctly
registering your objects.  If you are still having problems, you can use the
UnitOfWork.validateObjectSpace() method to
help debug where the error occurred.  For more information, see the manual
or FAQ.

Could somebody please tell me what the heck is going on? How can I make sure
my model and the DB stay synchronized and how can I make sure, that the
objects I access in memory have valid data structures that behave normally,
like you would expect them too?

Or do I always need to make a roundtrip to the DB if accessing a persisted
object's data? That can not be the point of a persistence architecture, can
it?

Thank You all in advance for the help,
Marek


--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25092854.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
In reply to this post by measwel
Hallo. The same thing happens, when using .equals. That seems not to be the problem. But, maybe I have a solution:

Now instead of accessing the user's favorite collection directly, I first get the user's reference from the Entity manger like so:

  public Wuser getUser() {

    EntityManager em = null;
    em = getEntityManager();

    // get the current user
    ExternalContext extContext = getContext().getExternalContext();
    Wuser user = (Wuser) extContext.getSessionMap().get("user");
    // get the user from the entity manager
    user = em.getReference(user.getClass(), user.getId());

    return user;
  }

This seems to work; I have not gotten the error up to now (fingers crossed). I supposed that the user object got detached somehow and by using the above method, I get a new reference to a manged instance. Could this have been the source of my problems? Is it normal to get references to objects which properties you want to use from the entity manager?

Thank you,
MPK
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Peter Ondruška
Did you override equals method for that class? Unless you did you cannot expect it to work correctly.

On Sat, Aug 22, 2009 at 3:54 PM, measwel <[hidden email]> wrote:

Hallo. The same thing happens, when using .equals. That seems not to be the
problem. But, maybe I have a solution:

Now instead of accessing the user's favorite collection directly, I first
get the user's reference from the Entity manger like so:

 public Wuser getUser() {

   EntityManager em = null;
   em = getEntityManager();

   // get the current user
   ExternalContext extContext = getContext().getExternalContext();
   Wuser user = (Wuser) extContext.getSessionMap().get("user");
   // get the user from the entity manager
   user = em.getReference(user.getClass(), user.getId());

   return user;
 }

This seems to work; I have not gotten the error up to now (fingers crossed).
I supposed that the user object got detached somehow and by using the above
method, I get a new reference to a manged instance. Could this have been the
source of my problems? Is it normal to get references to objects which
properties you want to use from the entity manager?

Thank you,
MPK
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25094044.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
Yes, here is the code:

@Override
  public boolean equals(Object object) {
    if (object == null || !this.getClass().equals(object.getClass())) {
      return false;
    }

    Movie other = (Movie) object;
    if (this.movieID != other.movieID && (this.movieID == null || !this.movieID.equals(other.movieID))) {
      return false;
    }

    return true;
  }

The comparison works correctly, if I get the user reference from the entity manager. Is that a correct thing to do?

Also : now sometimes if I wait for a long time I get the following error when trying to create a new favorite after waiting for a few minutes:

Cannot find faces context.

I am currently waiting to recreate the error, so I can post the error stack.
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
This is the error I am getting when trying to create a new favorite after waiting a couple of minutes. It is probably caused by my session timing out:

WARNING:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'movieID' cannot be null
Error Code: 1048
Call: INSERT INTO favorites (since, movieid, userid) VALUES (?, ?, ?)
Query: InsertObjectQuery(null)
        at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:313)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:757)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:823)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:557)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:500)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:855)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:204)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:190)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:325)
        at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:163)
        at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:178)
        at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:465)
        at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
        at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
        at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
        at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
        at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:666)
        at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:585)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:114)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2587)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:254)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:229)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:185)
        at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3129)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1241)
        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:478)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1330)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:2848)
        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:223)
        at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
        at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
        at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:411)
        at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:843)
        at com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:198)
        at jpa.controllers.FavoriteJpaController.create(FavoriteJpaController.java:79)
        at jsf.controllers.FavoriteController.addFavorite(FavoriteController.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        at javax.faces.component.UICommand.broadcast(UICommand.java:387)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
        at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
        at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
        at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
        at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'movieID' cannot be null
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2289)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2274)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:748)
        ... 86 more
WARNING:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'movieID' cannot be null
Error Code: 1048
Call: INSERT INTO favorites (since, movieid, userid) VALUES (?, ?, ?)
Query: InsertObjectQuery(null)
        at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:313)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:757)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:823)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:557)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:500)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:855)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:204)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:190)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:325)
        at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:163)
        at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:178)
        at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:465)
        at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
        at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
        at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
        at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
        at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:666)
        at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:585)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:114)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2587)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:254)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:229)
        at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:185)
        at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3129)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1241)
        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:478)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1330)
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:2848)
        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:223)
        at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
        at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
        at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:411)
        at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:843)
        at com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:198)
        at jpa.controllers.FavoriteJpaController.create(FavoriteJpaController.java:79)
        at jsf.controllers.FavoriteController.addFavorite(FavoriteController.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        at javax.faces.component.UICommand.broadcast(UICommand.java:387)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
        at org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
        at com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
        at com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
        at com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
        at com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
        at com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
        at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'movieID' cannot be null
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2289)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2274)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:748)

How can I prevent it? Should I check for a session time out?

Thanks,
MPK
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Peter Ondruška
In reply to this post by measwel
OK, but look at your equals, any Movie.equals (anyotherMovie), should be

if (this.property1 == object.property1 && ... ) return true

On Sat, Aug 22, 2009 at 4:09 PM, measwel <[hidden email]> wrote:

Yes, here is the code:

@Override
 public boolean equals(Object object) {
   if (object == null || !this.getClass().equals(object.getClass())) {
     return false;
   }

   Movie other = (Movie) object;
   if (this.movieID != other.movieID && (this.movieID == null ||
!this.movieID.equals(other.movieID))) {
     return false;
   }

   return true;
 }

The comparison works correctly, if I get the user reference from the entity
manager. Is that a correct thing to do?

Also : now sometimes if I wait for a long time I get the following error
when trying to create a new favorite after waiting for a few minutes:

Cannot find faces context.

I am currently waiting to recreate the error, so I can post the error stack.
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25094165.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
In reply to this post by measwel
When this exception occurs, how did you create the favorite?

Q

On Sat, Aug 22, 2009 at 4:23 PM, measwel <[hidden email]> wrote:

This is the error I am getting when trying to create a new favorite after
waiting a couple of minutes. It is probably caused by my session timing out:

WARNING:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build
20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column
'movieID' cannot be null
Error Code: 1048
Call: INSERT INTO favorites (since, movieid, userid) VALUES (?, ?, ?)
Query: InsertObjectQuery(null)
       at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:313)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:757)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:823)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:557)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:500)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:855)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:204)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:190)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:325)
       at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:163)
       at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:178)
       at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:465)
       at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
       at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
       at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
       at
org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
       at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:666)
       at
org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:585)
       at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:114)
       at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2587)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:254)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:229)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:185)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3129)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1241)
       at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:478)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1330)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:2848)
       at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:223)
       at
org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
       at
org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
       at
com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:411)
       at
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:843)
       at
com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:198)
       at
jpa.controllers.FavoriteJpaController.create(FavoriteJpaController.java:79)
       at
jsf.controllers.FavoriteController.addFavorite(FavoriteController.java:83)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
       at
com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
       at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
       at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
       at javax.faces.component.UICommand.broadcast(UICommand.java:387)
       at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
       at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
       at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
       at
org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
       at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
       at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
       at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
       at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
       at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
       at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
       at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
       at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
       at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
       at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
       at
com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
       at
com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
       at
com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
       at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
       at
com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
       at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
       at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
       at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
       at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
       at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
       at
com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
       at
com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
Caused by:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column
'movieID' cannot be null
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
       at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
       at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
       at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
       at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2289)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2274)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:748)
       ... 86 more
WARNING:
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build
20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column
'movieID' cannot be null
Error Code: 1048
Call: INSERT INTO favorites (since, movieid, userid) VALUES (?, ?, ?)
Query: InsertObjectQuery(null)
       at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:313)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:757)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:823)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:557)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:500)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:855)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:204)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:190)
       at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:325)
       at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:163)
       at
org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:178)
       at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:465)
       at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
       at
org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
       at
org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:290)
       at
org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
       at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:666)
       at
org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:585)
       at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:114)
       at
org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2587)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:254)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:229)
       at
org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:185)
       at
org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3129)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1241)
       at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:478)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1330)
       at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:2848)
       at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:223)
       at
org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
       at
org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
       at
com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:411)
       at
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:843)
       at
com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:198)
       at
jpa.controllers.FavoriteJpaController.create(FavoriteJpaController.java:79)
       at
jsf.controllers.FavoriteController.addFavorite(FavoriteController.java:83)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
       at
com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
       at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
       at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
       at javax.faces.component.UICommand.broadcast(UICommand.java:387)
       at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
       at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
       at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:431)
       at
org.apache.catalina.core.StandardWrapperValve.preInvoke(StandardWrapperValve.java:462)
       at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:139)
       at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:186)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
       at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
       at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
       at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
       at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:142)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:719)
       at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:657)
       at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:651)
       at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1030)
       at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
       at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:242)
       at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
       at
com.sun.grizzly.http.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:633)
       at
com.sun.grizzly.http.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:570)
       at
com.sun.grizzly.http.DefaultProcessorTask.process(DefaultProcessorTask.java:827)
       at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:152)
       at
com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
       at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
       at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
       at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
       at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
       at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
       at
com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:325)
       at
com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:184)
Caused by:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column
'movieID' cannot be null
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
       at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
       at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
       at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
       at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2289)
       at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2274)
       at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:748)

How can I prevent it? Should I check for a session time out?

Thanks,
MPK
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25094274.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
Here is the code:

public void create(Favorite favorite) throws PreexistingEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
      utx.begin();
      em = getEntityManager();
      // get the correct user reference
      Wuser user = favorite.getUser();
      if (user != null) {
        user = em.getReference(user.getClass(), user.getId());
        favorite.setUser(user);
      }
      Movie movie = favorite.getMovie();
      if (movie != null) {
        movie = em.getReference(movie.getClass(), movie.getMovieID());
        favorite.setMovie(movie);
      }
      favorite.setSince(new Date());
      em.persist(favorite);
      // add the new favorite also to the user's favorite collection
      if (user != null) {
        user.getFavorites().add(favorite);
        user = em.merge(user);
      }
      utx.commit();
    } catch (Exception ex) {
      try {
        utx.rollback();
      } catch (Exception re) {
        throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
      }
      if (findFavorite(favorite.getFavoriteId()) != null) {
        throw new PreexistingEntityException("Favorite " + favorite + " already exists.", ex);
      }
      throw ex;
    } finally {
      if (em != null) {
        em.close();
      }
    }
  }

It works fine, as long as I dont stay inactive too long on the page that has the button for creating a favorite.
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
I'm taking a wild one here.

Is it possible that when the session expires, that the Favorite.getMovie() perhaps returns NULL?

Can you describe the design in terms of your sessions like what is stored in the session and how do you decide when to store them there, how the movie is selected, and so on.

Q

On Sat, Aug 22, 2009 at 6:20 PM, measwel <[hidden email]> wrote:

Here is the code:

public void create(Favorite favorite) throws PreexistingEntityException,
RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     // get the correct user reference
     Wuser user = favorite.getUser();
     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }
     favorite.setSince(new Date());
     em.persist(favorite);
     // add the new favorite also to the user's favorite collection
     if (user != null) {
       user.getFavorites().add(favorite);
       user = em.merge(user);
     }
     utx.commit();
   } catch (Exception ex) {
     try {
       utx.rollback();
     } catch (Exception re) {
       throw new RollbackFailureException("An error occurred attempting to
roll back the transaction.", re);
     }
     if (findFavorite(favorite.getFavoriteId()) != null) {
       throw new PreexistingEntityException("Favorite " + favorite + "
already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }

It works fine, as long as I dont stay inactive too long on the page that has
the button for creating a favorite.
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25095264.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
Let me explain the reason I asked this.

The fact that the exception mentions movieId == NULL violated a constraint, obviously indicates that movieId was NULL.

So you need to figure out why it's NULL. The chances of something else going on is always possible and many things can be blamed, but I would say the best bet is to look for it being null. So try and trace through the code and check what the favorites object looks like before the persist() call.

Further, the user is most probably stored in the session, and this could cause (depending on your implementation) the user to be null, in which case you move on anyway? Same goes with your check if movie is not null, you simply move on? I would think if "movie" is null you cannot have a valid favorite, and therefore have an exception which should be raised to the caller.

I made some assumptions here, so please correct me where I'm wrong.

Q

On Sat, Aug 22, 2009 at 6:24 PM, Quintin Beukes <[hidden email]> wrote:
I'm taking a wild one here.

Is it possible that when the session expires, that the Favorite.getMovie() perhaps returns NULL?

Can you describe the design in terms of your sessions like what is stored in the session and how do you decide when to store them there, how the movie is selected, and so on.

Q


On Sat, Aug 22, 2009 at 6:20 PM, measwel <[hidden email]> wrote:

Here is the code:

public void create(Favorite favorite) throws PreexistingEntityException,
RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     // get the correct user reference
     Wuser user = favorite.getUser();
     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }
     favorite.setSince(new Date());
     em.persist(favorite);
     // add the new favorite also to the user's favorite collection
     if (user != null) {
       user.getFavorites().add(favorite);
       user = em.merge(user);
     }
     utx.commit();
   } catch (Exception ex) {
     try {
       utx.rollback();
     } catch (Exception re) {
       throw new RollbackFailureException("An error occurred attempting to
roll back the transaction.", re);
     }
     if (findFavorite(favorite.getFavoriteId()) != null) {
       throw new PreexistingEntityException("Favorite " + favorite + "
already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }

It works fine, as long as I dont stay inactive too long on the page that has
the button for creating a favorite.
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25095264.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes



--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
Even if the prior e-mail doesn't describe your problem, I would suggest, unless your design accommodates this, you replace the following code:
     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.
getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }

with something this:
     if (user == null) {
       throw new IllegalArgumentException("Favorite has no user.");
     }
     user = em.getReference(user.getClass(), user.getId());
     favorite.setUser(user);
     Movie movie = favorite.getMovie();
     if (movie == null) {
       throw new IllegalArgumentException("Favorite has no movie.");
     }
     movie = em.getReference(movie.
getClass(), movie.getMovieID());
     favorite.setMovie(movie);

I did so with the movie, because I can't imagine anyone being a favorite of a 'NULL' movie. And for the user since you mentioned the favorite button only being available when there is a session and the fact that 'NULL' can't really have favorites since it evaluates to NULL, the purest void ;>

regards,
Q


On Sat, Aug 22, 2009 at 6:28 PM, Quintin Beukes <[hidden email]> wrote:
Let me explain the reason I asked this.

The fact that the exception mentions movieId == NULL violated a constraint, obviously indicates that movieId was NULL.

So you need to figure out why it's NULL. The chances of something else going on is always possible and many things can be blamed, but I would say the best bet is to look for it being null. So try and trace through the code and check what the favorites object looks like before the persist() call.

Further, the user is most probably stored in the session, and this could cause (depending on your implementation) the user to be null, in which case you move on anyway? Same goes with your check if movie is not null, you simply move on? I would think if "movie" is null you cannot have a valid favorite, and therefore have an exception which should be raised to the caller.

I made some assumptions here, so please correct me where I'm wrong.

Q


On Sat, Aug 22, 2009 at 6:24 PM, Quintin Beukes <[hidden email]> wrote:
I'm taking a wild one here.

Is it possible that when the session expires, that the Favorite.getMovie() perhaps returns NULL?

Can you describe the design in terms of your sessions like what is stored in the session and how do you decide when to store them there, how the movie is selected, and so on.

Q


On Sat, Aug 22, 2009 at 6:20 PM, measwel <[hidden email]> wrote:

Here is the code:

public void create(Favorite favorite) throws PreexistingEntityException,
RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     // get the correct user reference
     Wuser user = favorite.getUser();
     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }
     favorite.setSince(new Date());
     em.persist(favorite);
     // add the new favorite also to the user's favorite collection
     if (user != null) {
       user.getFavorites().add(favorite);
       user = em.merge(user);
     }
     utx.commit();
   } catch (Exception ex) {
     try {
       utx.rollback();
     } catch (Exception re) {
       throw new RollbackFailureException("An error occurred attempting to
roll back the transaction.", re);
     }
     if (findFavorite(favorite.getFavoriteId()) != null) {
       throw new PreexistingEntityException("Favorite " + favorite + "
already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }

It works fine, as long as I dont stay inactive too long on the page that has
the button for creating a favorite.
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25095264.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes



--
Quintin Beukes



--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
Sorry for flooding so much... I'm not thinking properly, do the user and movie NULL checks at the beginning of the method.

Q

On Sat, Aug 22, 2009 at 6:37 PM, Quintin Beukes <[hidden email]> wrote:
Even if the prior e-mail doesn't describe your problem, I would suggest, unless your design accommodates this, you replace the following code:

     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.
getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }

with something this:
     if (user == null) {
       throw new IllegalArgumentException("Favorite has no user.");

     }
     user = em.getReference(user.getClass(), user.getId());
     favorite.setUser(user);
     Movie movie = favorite.getMovie();
     if (movie == null) {
       throw new IllegalArgumentException("Favorite has no movie.");
     }
     movie = em.getReference(movie.
getClass(), movie.getMovieID());
     favorite.setMovie(movie);

I did so with the movie, because I can't imagine anyone being a favorite of a 'NULL' movie. And for the user since you mentioned the favorite button only being available when there is a session and the fact that 'NULL' can't really have favorites since it evaluates to NULL, the purest void ;>

regards,
Q


On Sat, Aug 22, 2009 at 6:28 PM, Quintin Beukes <[hidden email]> wrote:
Let me explain the reason I asked this.

The fact that the exception mentions movieId == NULL violated a constraint, obviously indicates that movieId was NULL.

So you need to figure out why it's NULL. The chances of something else going on is always possible and many things can be blamed, but I would say the best bet is to look for it being null. So try and trace through the code and check what the favorites object looks like before the persist() call.

Further, the user is most probably stored in the session, and this could cause (depending on your implementation) the user to be null, in which case you move on anyway? Same goes with your check if movie is not null, you simply move on? I would think if "movie" is null you cannot have a valid favorite, and therefore have an exception which should be raised to the caller.

I made some assumptions here, so please correct me where I'm wrong.

Q


On Sat, Aug 22, 2009 at 6:24 PM, Quintin Beukes <[hidden email]> wrote:
I'm taking a wild one here.

Is it possible that when the session expires, that the Favorite.getMovie() perhaps returns NULL?

Can you describe the design in terms of your sessions like what is stored in the session and how do you decide when to store them there, how the movie is selected, and so on.

Q


On Sat, Aug 22, 2009 at 6:20 PM, measwel <[hidden email]> wrote:

Here is the code:

public void create(Favorite favorite) throws PreexistingEntityException,
RollbackFailureException, Exception {
   EntityManager em = null;
   try {
     utx.begin();
     em = getEntityManager();
     // get the correct user reference
     Wuser user = favorite.getUser();
     if (user != null) {
       user = em.getReference(user.getClass(), user.getId());
       favorite.setUser(user);
     }
     Movie movie = favorite.getMovie();
     if (movie != null) {
       movie = em.getReference(movie.getClass(), movie.getMovieID());
       favorite.setMovie(movie);
     }
     favorite.setSince(new Date());
     em.persist(favorite);
     // add the new favorite also to the user's favorite collection
     if (user != null) {
       user.getFavorites().add(favorite);
       user = em.merge(user);
     }
     utx.commit();
   } catch (Exception ex) {
     try {
       utx.rollback();
     } catch (Exception re) {
       throw new RollbackFailureException("An error occurred attempting to
roll back the transaction.", re);
     }
     if (findFavorite(favorite.getFavoriteId()) != null) {
       throw new PreexistingEntityException("Favorite " + favorite + "
already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }

It works fine, as long as I dont stay inactive too long on the page that has
the button for creating a favorite.
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25095264.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes



--
Quintin Beukes



--
Quintin Beukes



--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
In reply to this post by measwel
I will try to reproduce the error while debugging. Hang on.
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
In reply to this post by Quintin Beukes-2
Quintin,

I noticed my userBean was set to request type scope. I changed it to session type scope. It could explain why it was possible that the user was flushed out of memory while the user session was still active. I expect now, that the user will stay there untill the session times out and if this happens, then he should simply be redirected to the login page. I will post an update when I find out :)

Regards,
Marek
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
In reply to this post by Quintin Beukes-2
What is actually happening is this:

In the jsp page I have this for the command button to add a favorite:

        <h:commandButton id="submit"
                         value="Create Favorite"
                         rendered="#{true}"
                         action="#{FavoriteC.addFavorite}">
          <f:setPropertyActionListener target="#{FavoriteC.movie}" value="#{MovieC.movie}" />
        </h:commandButton>

FavoriteC is the Favorite Controller, MovieC is the movie Controller. It turns out that MovieC.movie returns null, so he can not set the movie for the Favorite. Somehow the movie Controller does no longer return the correct movie. Perhaps it became detached?

Note: the Movie Controller bean is set to session scope, so it should be there as long as the users session is still active.

If so then:

1) why / when do persistent objects become detached? Is there some kind of time limit?

Regards,
Marek
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

Quintin Beukes-2
What do you mean become detached? Detached from what? The session?

Try starting everything from clean (delete cookies and cache from both the server/client).

Then, when does the MovieC return null for a movie? How does the MovieC and FavoriteC determine what movie/favorite to return, iow. when/how are they populated?

Q

On Sat, Aug 22, 2009 at 7:12 PM, measwel <[hidden email]> wrote:

What is actually happening is this:

In the jsp page I have this for the command button to add a favorite:

       <h:commandButton id="submit"
                        value="Create Favorite"
                        rendered="#{true}"
                        action="#{FavoriteC.addFavorite}">
         <f:setPropertyActionListener target="#{FavoriteC.movie}"
value="#{MovieC.movie}" />
       </h:commandButton>

FavoriteC is the Favorite Controller, MovieC is the movie Controller. It
turns out that MovieC.movie returns null, so he can not set the movie for
the Favorite. Somehow the movie Controller does no longer return the correct
movie. Perhaps it became detached?

Note: the Movie Controller bean is set to session scope, so it should be
there as long as the users session is still active.

If so then:

1) why / when do persistent objects become detached? Is there some kind of
time limit?

Regards,
Marek
--
View this message in context: http://www.nabble.com/JPA-error-tp25092854p25095709.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.




--
Quintin Beukes
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
The error is hard to reproduce, as I have to wait some time in order for it to appear :( . If I wait to long, the session times out and then the user is simply sent to the login screen. MovieC.movie is set when the user choses a movie from the list of movies.

Take a look for yourself: movies.dyndns.tv/Recommend.

The server is mostly up, but sometimes it may be down. I will stop the debug so you can take a look. Make a list of favorites, then try adding a favorite after some time passes (I think about 10 minutes).

Regards,
Marek

PS I have not yet implemented any recommendation algorithms, so please dont look at that part.
Reply | Threaded
Open this post in threaded view
|

Re: JPA error

measwel
In reply to this post by Quintin Beukes-2
Quintin, as an update; I have not been able to reproduce the error. The app works fine so far, so I am dropping the matter untill I see the error reemerge. Thanks for you input. I will add the null check anyhow.

Regards,
Marek
12