You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "Trenton D. Adams" <tr...@trentonadams.ca> on 2010/05/26 02:09:56 UTC

Inappropriate error message

I was getting the following error with openjpa 1.2.1...
        <openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged object in persistent field "org.adamsbros.rmi.ledger.journal.JournalEntry.journalType" during flush.  However, this field does not allow cascade persist. Set the cascade attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), or enable cascade-persist globally, or manually persist the related field value prior to flushing. You cannot flush unmanaged objects or graphs that have persistent associations to unmanaged objects.         

JournalEntry.journalType defined as...
    @ManyToOne
    @JoinColumn(name = "journal_type", referencedColumnName = "journal_type",
        nullable = false, table = "journal")

JournalType constructor was like this...
    @Id
    @Column(name = "journal_type")
    private String journalType;

    @Column(name = "description")
    private String description;

    public JournalType()
    {
    }
    // empty as you can see
    public JournalType(final String journalType)
    {
    }

Keep in mind that I do not want cascading to occur with the journalType in JournalEntry, as I will manage them separately.

As a result, creating a new JournalType would always result in empty instance variables.  I would have expected something like this from the postgresql db...
open_accounting=> INSERT INTO journal_types VALUES(null, null);
ERROR:  null value in column "journal_type" violates not-null constraint

But instead I get the obscure error about unmanaged objects.

Not sure if something similar would happen in openjpa 2, as openejb is not yet configured to use it.  But, if it does do the same thing, I would highly recommend changing something.  This took me about 20-30 minutes to see, maybe longer.  I was trying to compare my entities with other entities that were doing the exact same thing, and couldn't see any problems.  It just seemed so odd.  And it was all because my constructor was not doing it's proper initialization of the instance variables, from the values passed in.

Would you like me to post a bug report?

RE: Inappropriate error message

Posted by Pinaki Poddar <pp...@apache.org>.
> In my experience 75% of all of my issues disappear if I use build time
enhancement.

Yep. Spread that message. 
non-build time enhancements (there are +4 flavors of them since I last
counted) can cause errors that surface out very far from their point of
origin. 


-----
Pinaki 
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Inappropriate-error-message-tp5101321p5105358.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

RE: Inappropriate error message

Posted by C N Davies <cn...@cndavies.com>.
Using Ant to enhance the classes at build time using org.apache.openjpa.ant.PCEnhancerTask

In my experience 75% of all of my issues disappear if I use build time enhancement. 

Chris


-----Original Message-----
From: Trenton D. Adams [mailto:trent@trentonadams.ca] 
Sent: Wednesday, 26 May 2010 11:16 AM
To: users@openjpa.apache.org; cnd@cndavies.com
Subject: Re: Inappropriate error message

Build time enhancement?

----- "C N Davies" <cn...@cndavies.com> wrote:

> From: "C N Davies" <cn...@cndavies.com>
> To: users@openjpa.apache.org
> Sent: Tuesday, May 25, 2010 7:32:11 PM GMT -07:00 US/Canada Mountain
> Subject: RE: Inappropriate error message
>
> I raised this point about a year ago, this seems to be a catch all
> error because I would also get it on null fields intermittently when
> there was no DB constraint in effect. This was fixed by build time
> enhancement, but if you have a DB constraint then it doesn't seen to
> fix it as you have reported.   It doesn't appear to happen in 2.0.
> 
> Chris
> 
> 
> 
> -----Original Message-----
> From: Trenton D. Adams [mailto:trent@trentonadams.ca] 
> Sent: Wednesday, 26 May 2010 10:10 AM
> To: users@openjpa.apache.org
> Subject: Inappropriate error message
> 
> I was getting the following error with openjpa 1.2.1...
>         <openjpa-1.2.1-r752877:753278 fatal user error>
> org.apache.openjpa.persistence.InvalidStateException: Encountered
> unmanaged object in persistent field
> "org.adamsbros.rmi.ledger.journal.JournalEntry.journalType" during
> flush.  However, this field does not allow cascade persist. Set the
> cascade attribute for this field to CascadeType.PERSIST or
> CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml),
> or enable cascade-persist globally, or manually persist the related
> field value prior to flushing. You cannot flush unmanaged objects or
> graphs that have persistent associations to unmanaged objects.        
> 
> 
> JournalEntry.journalType defined as...
>     @ManyToOne
>     @JoinColumn(name = "journal_type", referencedColumnName =
> "journal_type",
>         nullable = false, table = "journal")
> 
> JournalType constructor was like this...
>     @Id
>     @Column(name = "journal_type")
>     private String journalType;
> 
>     @Column(name = "description")
>     private String description;
> 
>     public JournalType()
>     {
>     }
>     // empty as you can see
>     public JournalType(final String journalType)
>     {
>     }
> 
> Keep in mind that I do not want cascading to occur with the
> journalType in JournalEntry, as I will manage them separately.
> 
> As a result, creating a new JournalType would always result in empty
> instance variables.  I would have expected something like this from
> the postgresql db...
> open_accounting=> INSERT INTO journal_types VALUES(null, null);
> ERROR:  null value in column "journal_type" violates not-null
> constraint
> 
> But instead I get the obscure error about unmanaged objects.
> 
> Not sure if something similar would happen in openjpa 2, as openejb is
> not yet configured to use it.  But, if it does do the same thing, I
> would highly recommend changing something.  This took me about 20-30
> minutes to see, maybe longer.  I was trying to compare my entities
> with other entities that were doing the exact same thing, and couldn't
> see any problems.  It just seemed so odd.  And it was all because my
> constructor was not doing it's proper initialization of the instance
> variables, from the values passed in.
> 
> Would you like me to post a bug report?


Re: Inappropriate error message

Posted by Donald Woods <dw...@apache.org>.
http://openjpa.apache.org/entity-enhancement.html


-Donald


On 5/25/10 9:15 PM, Trenton D. Adams wrote:
> Build time enhancement?
> 
> ----- "C N Davies" <cn...@cndavies.com> wrote:
> 
>> From: "C N Davies" <cn...@cndavies.com>
>> To: users@openjpa.apache.org
>> Sent: Tuesday, May 25, 2010 7:32:11 PM GMT -07:00 US/Canada Mountain
>> Subject: RE: Inappropriate error message
>>
>> I raised this point about a year ago, this seems to be a catch all
>> error because I would also get it on null fields intermittently when
>> there was no DB constraint in effect. This was fixed by build time
>> enhancement, but if you have a DB constraint then it doesn't seen to
>> fix it as you have reported.   It doesn't appear to happen in 2.0.
>>
>> Chris
>>
>>
>>
>> -----Original Message-----
>> From: Trenton D. Adams [mailto:trent@trentonadams.ca] 
>> Sent: Wednesday, 26 May 2010 10:10 AM
>> To: users@openjpa.apache.org
>> Subject: Inappropriate error message
>>
>> I was getting the following error with openjpa 1.2.1...
>>         <openjpa-1.2.1-r752877:753278 fatal user error>
>> org.apache.openjpa.persistence.InvalidStateException: Encountered
>> unmanaged object in persistent field
>> "org.adamsbros.rmi.ledger.journal.JournalEntry.journalType" during
>> flush.  However, this field does not allow cascade persist. Set the
>> cascade attribute for this field to CascadeType.PERSIST or
>> CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml),
>> or enable cascade-persist globally, or manually persist the related
>> field value prior to flushing. You cannot flush unmanaged objects or
>> graphs that have persistent associations to unmanaged objects.        
>>
>>
>> JournalEntry.journalType defined as...
>>     @ManyToOne
>>     @JoinColumn(name = "journal_type", referencedColumnName =
>> "journal_type",
>>         nullable = false, table = "journal")
>>
>> JournalType constructor was like this...
>>     @Id
>>     @Column(name = "journal_type")
>>     private String journalType;
>>
>>     @Column(name = "description")
>>     private String description;
>>
>>     public JournalType()
>>     {
>>     }
>>     // empty as you can see
>>     public JournalType(final String journalType)
>>     {
>>     }
>>
>> Keep in mind that I do not want cascading to occur with the
>> journalType in JournalEntry, as I will manage them separately.
>>
>> As a result, creating a new JournalType would always result in empty
>> instance variables.  I would have expected something like this from
>> the postgresql db...
>> open_accounting=> INSERT INTO journal_types VALUES(null, null);
>> ERROR:  null value in column "journal_type" violates not-null
>> constraint
>>
>> But instead I get the obscure error about unmanaged objects.
>>
>> Not sure if something similar would happen in openjpa 2, as openejb is
>> not yet configured to use it.  But, if it does do the same thing, I
>> would highly recommend changing something.  This took me about 20-30
>> minutes to see, maybe longer.  I was trying to compare my entities
>> with other entities that were doing the exact same thing, and couldn't
>> see any problems.  It just seemed so odd.  And it was all because my
>> constructor was not doing it's proper initialization of the instance
>> variables, from the values passed in.
>>
>> Would you like me to post a bug report?
> 

Re: Inappropriate error message

Posted by "Trenton D. Adams" <tr...@trentonadams.ca>.
Build time enhancement?

----- "C N Davies" <cn...@cndavies.com> wrote:

> From: "C N Davies" <cn...@cndavies.com>
> To: users@openjpa.apache.org
> Sent: Tuesday, May 25, 2010 7:32:11 PM GMT -07:00 US/Canada Mountain
> Subject: RE: Inappropriate error message
>
> I raised this point about a year ago, this seems to be a catch all
> error because I would also get it on null fields intermittently when
> there was no DB constraint in effect. This was fixed by build time
> enhancement, but if you have a DB constraint then it doesn't seen to
> fix it as you have reported.   It doesn't appear to happen in 2.0.
> 
> Chris
> 
> 
> 
> -----Original Message-----
> From: Trenton D. Adams [mailto:trent@trentonadams.ca] 
> Sent: Wednesday, 26 May 2010 10:10 AM
> To: users@openjpa.apache.org
> Subject: Inappropriate error message
> 
> I was getting the following error with openjpa 1.2.1...
>         <openjpa-1.2.1-r752877:753278 fatal user error>
> org.apache.openjpa.persistence.InvalidStateException: Encountered
> unmanaged object in persistent field
> "org.adamsbros.rmi.ledger.journal.JournalEntry.journalType" during
> flush.  However, this field does not allow cascade persist. Set the
> cascade attribute for this field to CascadeType.PERSIST or
> CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml),
> or enable cascade-persist globally, or manually persist the related
> field value prior to flushing. You cannot flush unmanaged objects or
> graphs that have persistent associations to unmanaged objects.        
> 
> 
> JournalEntry.journalType defined as...
>     @ManyToOne
>     @JoinColumn(name = "journal_type", referencedColumnName =
> "journal_type",
>         nullable = false, table = "journal")
> 
> JournalType constructor was like this...
>     @Id
>     @Column(name = "journal_type")
>     private String journalType;
> 
>     @Column(name = "description")
>     private String description;
> 
>     public JournalType()
>     {
>     }
>     // empty as you can see
>     public JournalType(final String journalType)
>     {
>     }
> 
> Keep in mind that I do not want cascading to occur with the
> journalType in JournalEntry, as I will manage them separately.
> 
> As a result, creating a new JournalType would always result in empty
> instance variables.  I would have expected something like this from
> the postgresql db...
> open_accounting=> INSERT INTO journal_types VALUES(null, null);
> ERROR:  null value in column "journal_type" violates not-null
> constraint
> 
> But instead I get the obscure error about unmanaged objects.
> 
> Not sure if something similar would happen in openjpa 2, as openejb is
> not yet configured to use it.  But, if it does do the same thing, I
> would highly recommend changing something.  This took me about 20-30
> minutes to see, maybe longer.  I was trying to compare my entities
> with other entities that were doing the exact same thing, and couldn't
> see any problems.  It just seemed so odd.  And it was all because my
> constructor was not doing it's proper initialization of the instance
> variables, from the values passed in.
> 
> Would you like me to post a bug report?

RE: Inappropriate error message

Posted by C N Davies <cn...@cndavies.com>.
I raised this point about a year ago, this seems to be a catch all error because I would also get it on null fields intermittently when there was no DB constraint in effect. This was fixed by build time enhancement, but if you have a DB constraint then it doesn't seen to fix it as you have reported.   It doesn't appear to happen in 2.0.

Chris



-----Original Message-----
From: Trenton D. Adams [mailto:trent@trentonadams.ca] 
Sent: Wednesday, 26 May 2010 10:10 AM
To: users@openjpa.apache.org
Subject: Inappropriate error message

I was getting the following error with openjpa 1.2.1...
        <openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged object in persistent field "org.adamsbros.rmi.ledger.journal.JournalEntry.journalType" during flush.  However, this field does not allow cascade persist. Set the cascade attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), or enable cascade-persist globally, or manually persist the related field value prior to flushing. You cannot flush unmanaged objects or graphs that have persistent associations to unmanaged objects.         

JournalEntry.journalType defined as...
    @ManyToOne
    @JoinColumn(name = "journal_type", referencedColumnName = "journal_type",
        nullable = false, table = "journal")

JournalType constructor was like this...
    @Id
    @Column(name = "journal_type")
    private String journalType;

    @Column(name = "description")
    private String description;

    public JournalType()
    {
    }
    // empty as you can see
    public JournalType(final String journalType)
    {
    }

Keep in mind that I do not want cascading to occur with the journalType in JournalEntry, as I will manage them separately.

As a result, creating a new JournalType would always result in empty instance variables.  I would have expected something like this from the postgresql db...
open_accounting=> INSERT INTO journal_types VALUES(null, null);
ERROR:  null value in column "journal_type" violates not-null constraint

But instead I get the obscure error about unmanaged objects.

Not sure if something similar would happen in openjpa 2, as openejb is not yet configured to use it.  But, if it does do the same thing, I would highly recommend changing something.  This took me about 20-30 minutes to see, maybe longer.  I was trying to compare my entities with other entities that were doing the exact same thing, and couldn't see any problems.  It just seemed so odd.  And it was all because my constructor was not doing it's proper initialization of the instance variables, from the values passed in.

Would you like me to post a bug report?