You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Ritika Maheshwari <ri...@gmail.com> on 2007/01/12 20:56:52 UTC

pessimistic locking

I have the following properties defined in my persistence.xml


<property name="openjpa.LockManager" value="pessimistic"/>

<property name="openjpa.ReadLockLevel" value="read"/>

<property name="openjpa.WriteLockLevel" value="write"/>

<property name="openjpa.LockTimeout" value="30000"/>

Even then the sql for the  query

em.createQuery("select object(o) from Neworders o where
o.no_w_id=:warehouseId and o.no_d_id=:districtId ")

does not have the With RS USE AND KEEP UPDATE LOCKS.

However if I make the following change

 OpenJPAQuery qry  = OpenJPAPersistence.cast(em.createQuery("select
object(o) from Neworders o where o.no_w_id=:warehouseId and
o.no_d_id=:districtId "));
           qry.setParameter("warehouseId",wareHouseId);
           qry.setParameter("districtId",distId);
           qry.getFetchPlan().setReadLockMode(LockModeType.READ);
        newOrdersSet = qry.getResultList();

Then the sql generated has the WITH RS USE AND KEEP UPDATE LOCKS CLAUSE.

So howcome JPA thinks it is in Optimistic mode even when the
persistence.xmlsets LockManager to pessimitic and when you set the
ReadLockMode on fetch
plan then it thinks you are in pessimistic mode.Is there some
misunderstanding or is this a bug.So essentially my question was that by
just specifying the properties of Lock Manager and ReadLockMode in the
persistence.xml all the queries generated by JPA should have had the Update
Clause.But that did not happen.I had to specifically set the ReadLockMode on
the Fetchplan of the query to make the Update clause appear.

ritika

Re: @ForeignKey not allowed for @ManyToMany

Posted by Vlad Tatavu <vt...@ca.ibm.com>.
I wouldn't say that's obvious, but it make sense and it works.  Thanks!

Vlad




Abe White <aw...@bea.com> 
12/01/2007 03:24 PM
Please respond to
open-jpa-dev@incubator.apache.org


To
open-jpa-dev@incubator.apache.org
cc

Subject
Re: @ForeignKey not allowed for @ManyToMany






> Is there a reason why @ForeignKey is not allowed for @ManyToMany?

Because the field value is a collection, not a reference.  You want 
to use @ElementForeignKey.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.


Re: @ForeignKey not allowed for @ManyToMany

Posted by Abe White <aw...@bea.com>.
> Is there a reason why @ForeignKey is not allowed for @ManyToMany?

Because the field value is a collection, not a reference.  You want  
to use @ElementForeignKey.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

@ForeignKey not allowed for @ManyToMany

Posted by Vlad Tatavu <vt...@ca.ibm.com>.
Is there a reason why @ForeignKey is not allowed for @ManyToMany?

Vlad

RE: MappingTool does not create "not null" column for @ManyToOne(optional=false)

Posted by Vlad Tatavu <vt...@ca.ibm.com>.
I don't have the OpenJPA code, so I cannot look at it.

You are right, OpenJPA will enforce the constraint in Java, but I expect 
the MappingTool to apply the NOT NULL to the database for the attribute 
that is annotated with @ManyToOne - not to the "remote" attribute.

Example:
@Entity
public class TestAssociation {
        @Id
        @GeneratedValue
        public int id;
 
        @ManyToOne(optional=false)
        @ForeignKey
        TestEntity assoced;
}
The MappingTool executes the following commands for this class:
CREATE TABLE TestAssociation (id INTEGER NOT NULL, assoced_id INTEGER, 
PRIMARY KEY (id))
ALTER TABLE TestAssociation ADD FOREIGN KEY (assoced_id) REFERENCES 
TestEntity (id)

I expect the TestAssociation.assoced_id to be NOT NULL, not TestEntity.id. 
 TestEntity.id is NOT NULL already because it is primary key.

Vlad





"Patrick Linskey" <pl...@bea.com> 
12/01/2007 04:00 PM
Please respond to
open-jpa-dev@incubator.apache.org


To
<op...@incubator.apache.org>
cc

Subject
RE: MappingTool does not create "not null" column for 
@ManyToOne(optional=false)






See AnnotationPersistenceMetaDataParser.java:1201: if optional is false,
then OpenJPA (not the database) will throw an exception if a null is
specified. This is not propagated to foreign key constraints; those
should be configured via the @ForeignKey annotation, by setting the
updateAction appropriately.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc. 

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Vlad Tatavu [mailto:vtatavu@ca.ibm.com] 
> Sent: Friday, January 12, 2007 12:44 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: MappingTool does not create "not null" column for 
> @ManyToOne(optional=false)
> 
> If I use @ManyToOne(optional=false) to annotate an attribute, the 
> MappingTool does not create a NOT NULL column in the 
> corresponding table. 
> Bug?
> 
> Vlad
> 


RE: MappingTool does not create "not null" column for @ManyToOne(optional=false)

Posted by Patrick Linskey <pl...@bea.com>.
See AnnotationPersistenceMetaDataParser.java:1201: if optional is false,
then OpenJPA (not the database) will throw an exception if a null is
specified. This is not propagated to foreign key constraints; those
should be configured via the @ForeignKey annotation, by setting the
updateAction appropriately.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc. 

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Vlad Tatavu [mailto:vtatavu@ca.ibm.com] 
> Sent: Friday, January 12, 2007 12:44 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: MappingTool does not create "not null" column for 
> @ManyToOne(optional=false)
> 
> If I use @ManyToOne(optional=false) to annotate an attribute, the 
> MappingTool does not create a NOT NULL column in the 
> corresponding table. 
> Bug?
> 
> Vlad
> 

MappingTool does not create "not null" column for @ManyToOne(optional=false)

Posted by Vlad Tatavu <vt...@ca.ibm.com>.
If I use @ManyToOne(optional=false) to annotate an attribute, the 
MappingTool does not create a NOT NULL column in the corresponding table. 
Bug?

Vlad

Re: pessimistic locking

Posted by Marc Prud'hommeaux <mp...@apache.org>.
I think you also want to set "openjpa.Optimistic" to "false". That  
will default to non-optimistic transactions.

Setting the other properties ("openjpa.LockManager",  
"openjpa.ReadLockLevel", "openjpa.WriteLockLevel") are probably  
unnecessary.



On Jan 12, 2007, at 11:56 AM, Ritika Maheshwari wrote:

> I have the following properties defined in my persistence.xml
>
>
> <property name="openjpa.LockManager" value="pessimistic"/>
>
> <property name="openjpa.ReadLockLevel" value="read"/>
>
> <property name="openjpa.WriteLockLevel" value="write"/>
>
> <property name="openjpa.LockTimeout" value="30000"/>
>
> Even then the sql for the  query
>
> em.createQuery("select object(o) from Neworders o where
> o.no_w_id=:warehouseId and o.no_d_id=:districtId ")
>
> does not have the With RS USE AND KEEP UPDATE LOCKS.
>
> However if I make the following change
>
> OpenJPAQuery qry  = OpenJPAPersistence.cast(em.createQuery("select
> object(o) from Neworders o where o.no_w_id=:warehouseId and
> o.no_d_id=:districtId "));
>           qry.setParameter("warehouseId",wareHouseId);
>           qry.setParameter("districtId",distId);
>           qry.getFetchPlan().setReadLockMode(LockModeType.READ);
>        newOrdersSet = qry.getResultList();
>
> Then the sql generated has the WITH RS USE AND KEEP UPDATE LOCKS  
> CLAUSE.
>
> So howcome JPA thinks it is in Optimistic mode even when the
> persistence.xmlsets LockManager to pessimitic and when you set the
> ReadLockMode on fetch
> plan then it thinks you are in pessimistic mode.Is there some
> misunderstanding or is this a bug.So essentially my question was  
> that by
> just specifying the properties of Lock Manager and ReadLockMode in the
> persistence.xml all the queries generated by JPA should have had  
> the Update
> Clause.But that did not happen.I had to specifically set the  
> ReadLockMode on
> the Fetchplan of the query to make the Update clause appear.
>
> ritika