openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Beaumont <bruce.beaum...@ucs-solutions.co.za>
Subject Re: Bulk Update
Date Tue, 04 Dec 2007 11:04:43 GMT
Hi

Followup on using the latest snapshot for this error:

when running the following code:

EntityManagerFactory emf =
Persistence.createEntityManagerFactory("BRUCE-DEV");
EntityManager em = emf.createEntityManager();
EntityTransaction et = em.getTransaction();
    
et.begin();
Query q = em.createQuery("update simple x set x.description = ?1, x.dec
= ?2, x.date = ?3 where x.id = ?4");
q.setParameter(1, "Test 123");
q.setParameter(2, new BigDecimal("1234.56"));
q.setParameter(3, Calendar.getInstance());
q.setParameter(4, 2l);
int i = q.executeUpdate();
log.debug("Update " + i);
et.commit();


I get 

45  BRUCE-DEV  INFO   [main] openjpa.Runtime - Starting OpenJPA
1.1.0-SNAPSHOT
156  BRUCE-DEV  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.InformixDictionary".
1355  BRUCE-DEV  TRACE  [main] openjpa.jdbc.SQL - <t 28708894, conn
31212095> executing prepstmnt 20391510 SELECT t0.s_id, t0.s_date,
t0.s_decimal, t0.s_desc, t0.s_dt, t0.s_key FROM simple t0 WHERE (t0.s_id
= ?) [params=(long) 2]
1357  BRUCE-DEV  TRACE  [main] openjpa.jdbc.SQL - <t 28708894, conn
31212095> [2 ms] spent
Exception in thread "main" <openjpa-1.1.0-SNAPSHOT-r420667:599596
nonfatal user error> org.apache.openjpa.persistence.ArgumentException:
org.apache.openjpa.jdbc.kernel.exps.PCPath cannot be cast to
org.apache.openjpa.meta.FieldMetaData
	at
org.apache.openjpa.kernel.QueryImpl.updateInMemory(QueryImpl.java:1055)
	at org.apache.openjpa.kernel.ExpressionStoreQuery
$DataStoreExecutor.executeUpdate(ExpressionStoreQuery.java:693)
	at org.apache.openjpa.kernel.QueryImpl.update(QueryImpl.java:1038)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:808)
	at org.apache.openjpa.kernel.QueryImpl.updateAll(QueryImpl.java:883)
	at
org.apache.openjpa.kernel.DelegatingQuery.updateAll(DelegatingQuery.java:573)
	at
org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:319)
	at openjpa.TestUpd.run(TestUpd.java:37)
	at openjpa.TestUpd.main(TestUpd.java:50)
Caused by: java.lang.ClassCastException:
org.apache.openjpa.jdbc.kernel.exps.PCPath cannot be cast to
org.apache.openjpa.meta.FieldMetaData
	at
org.apache.openjpa.kernel.QueryImpl.updateInMemory(QueryImpl.java:1069)
	at
org.apache.openjpa.kernel.QueryImpl.updateInMemory(QueryImpl.java:1050)
	... 8 more



The error line is on the executeUpdate statement

Bruce


On Mon, 2007-12-03 at 14:46 -0800, plinskey@gmail.com wrote:
> Hi,
> 
> A couple of guesses:
> 
> - have you already modified anything in the transaction before calling
> executeUpdate()? This could trigger OpenJPA to do the update in memory
> in some situations, which would explain the SELECT.
> 
> - I think that the sadly-unlocalized message is caused by your attempt
> to update the calendar field. I don't know if this is a spec
> limitation or a product problem.
> 
> - recently, a few limitations around use of parameters in bulk updates
> were resolved. I don't remember the details of the issue, but just
> bear in mind that there are differences in the latest 1.1.0 snapshots
> compared to 1.0 or older snapshots.
> 
> - it looks like you are using the bulk update facilities to update
> just a single record (since you're using an id comparison in the WHERE
> clause.  Is this the case? Typically, bulk updates are best used when
> updating many records, not just a single record.
> 
> -Patrick
> 
> -Patrick
> 
> On 12/3/07, Bruce Beaumont <bruce.beaumont@ucs-solutions.co.za> wrote:
> > Hi
> >
> > I have a bean with the following mapping
> > @Id
> > @Column(name="s_id", nullable=false)
> > private long id = 0;
> >
> > @Basic
> > @Column(name="s_key", length=10, nullable=true)
> > private String key = null;
> >
> > @Basic
> > @Column(name="s_desc", length=30, nullable=true)
> > private String description = null;
> >
> > @Basic
> > @Column(name="s_decimal", scale=14, precision=2, nullable=true)
> > public BigDecimal dec = null;
> >
> > @Basic
> > @Column(name="s_date", nullable=true)
> > public Calendar date = null;
> >
> > @Basic
> > @Column(name="s_dt", nullable=true)
> > public Calendar dt = null;
> >
> > and am trying to do a bulk update as follows
> >
> > Query q = em.createQuery("update simple x set x.description = ?1, x.dec
> > = ?2, x.date = ?3 where x.id = ?4");
> > q.setParameter(1, "Test 123");
> > q.setParameter(2, new BigDecimal("1234.56"));
> > q.setParameter(3, Calendar.getInstance());
> > q.setParameter(4, 2l);
> >
> > I get the following error:
> > 35  BRUCE-DEV  INFO   [main] openjpa.Runtime - Starting OpenJPA 1.0.1
> > 167  BRUCE-DEV  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
> > "org.apache.openjpa.jdbc.sql.InformixDictionary".
> > 1344  BRUCE-DEV  TRACE  [main] openjpa.jdbc.SQL - <t 13359904, conn
> > 27211574> executing prepstmnt 8499707 SELECT t0.s_id, t0.s_date,
> > t0.s_decimal, t0.s_desc, t0.s_dt, t0.s_key FROM simple t0 WHERE (t0.s_id
> > = ?) [params=(long) 2]
> > 1346  BRUCE-DEV  TRACE  [main] openjpa.jdbc.SQL - <t 13359904, conn
> > 27211574> [1 ms] spent
> > Exception in thread "main" <openjpa-1.0.1-r420667:592145 nonfatal user
> > error> org.apache.openjpa.persistence.ArgumentException:
> > only-update-primitives
> > 	at
> > org.apache.openjpa.kernel.QueryImpl.updateInMemory(QueryImpl.java:1149)
> > 	at
> > org.apache.openjpa.kernel.QueryImpl.updateInMemory(QueryImpl.java:1051)
> > 	at org.apache.openjpa.kernel.ExpressionStoreQuery
> > $DataStoreExecutor.executeUpdate(ExpressionStoreQuery.java:692)
> > 	at org.apache.openjpa.kernel.QueryImpl.update(QueryImpl.java:1039)
> > 	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:803)
> > 	at org.apache.openjpa.kernel.QueryImpl.updateAll(QueryImpl.java:878)
> > 	at
> > org.apache.openjpa.kernel.DelegatingQuery.updateAll(DelegatingQuery.java:573)
> > 	at
> > org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:319)
> > 	at openjpa.TestUpd.run(TestUpd.java:42)
> > 	at openjpa.TestUpd.main(TestUpd.java:57)
> >
> > The strange thing is that if I remove the where clause it works OK. If I
> > use a fetch and change the bean values it works as well.
> >
> > Could anyone please give an indication for this error.
> >
> > Bruce
> >
> > PS: The select indicated in the trace is also a bit odd as it is not in
> > my small test program and I do not understand why it is there. It is not
> > there if there is no where clause.
> >
> >
> 
> 


Mime
View raw message