Note that there are some explanatory texts on larger screens.

plurals
  1. POTimeout trying to lock table when trying to merge
    text
    copied!<p>I am trying to write a test for a dropbox crawler.</p> <p>I have setup a Fixture which loads data into the database on load. </p> <pre><code>Fixtures.deleteDatabase(); Fixtures.loadModels("testusers.yaml"); </code></pre> <p>The problem occurs when the code </p> <pre><code>da = da.merge(); //exceptions gets thrown here </code></pre> <p>is reached. It throws an JdbcSQLException:</p> <pre><code>org.h2.jdbc.JdbcSQLException: Timeout trying to lock table "USER"; SQL statement: select user0_.id as id7_0_, user0_.activationSent as activati2_7_0_, user0_.confirmationCode as confirma3_7_0_, user0_.email as email7_0_, user0_.first_name as first5_7_0_, user0_.isAdmin as isAdmin7_0_, user0_.lastLogin as lastLogin7_0_, user0_.last_name as last8_7_0_, user0_.passwordHash as password9_7_0_, user0_.recoverPasswordCode as recover10_7_0_, user0_.referralCode as referra11_7_0_, user0_.signupDate as signupDate7_0_ from User user0_ where user0_.id=? [50200-149] at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) at org.h2.message.DbException.get(DbException.java:167) at org.h2.message.DbException.get(DbException.java:144) at org.h2.table.RegularTable.doLock(RegularTable.java:499) at org.h2.table.RegularTable.lock(RegularTable.java:433) at org.h2.table.TableFilter.lock(TableFilter.java:140) at org.h2.command.dml.Select.queryWithoutCache(Select.java:571) at org.h2.command.dml.Query.query(Query.java:257) at org.h2.command.dml.Query.query(Query.java:227) at org.h2.command.CommandContainer.query(CommandContainer.java:78) at org.h2.command.Command.executeQuery(Command.java:178) at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:96) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) at org.hibernate.loader.Loader.doQuery(Loader.java:802) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) at org.hibernate.loader.Loader.loadEntity(Loader.java:2037) ... 36 more </code></pre> <p>UpdateDropboxRowJob.java where the exception gets thrown</p> <pre><code>package mashpan.crawl.jobs; import play.Logger; import play.jobs.*; import models.DropboxAuthentication; public class UpdateDropboxRowJob extends Job { private DropboxAuthentication da; private long count; private boolean crawled; public UpdateDropboxRowJob(DropboxAuthentication da, long count, boolean crawled) { Logger.debug("[UpdateDropboxRowJob] ctor: " +",[da=" + (da == null ? "null" : da.toString()) + "]" +", count=[" + count + "]" +", crawled=[" + crawled + "]" ); this.da = da; this.count = count; this.crawled = crawled; } @Override public void doJob() throws Exception { Logger.debug("[UpdateDropboxRowJob] doJob: " +"da=[" + (da == null ? "null" : da.toString()) + "]" +"count=[" + count + "]" +"crawled=[" + crawled + "]" +"da.count"+(da == null ? "da==null" : da.count) + "]" ); da = da.merge(); //exceptions gets thrown here da.count = this.count; da.crawled = this.crawled; da.save(); } } @Entity public class DropboxAuthentication extends Model { public String type; //public String email; public String token_key; public String token_secret; public long count; public boolean crawled; public byte[] cipher; public byte[] iv; public long lastCrawlTime; @OneToOne public User user; public DropboxAuthentication(String type, byte[] cipher, byte[] iv, String token_key, String token_secret, User u, Date issueDate) { this.type = type; this.cipher = cipher; this.iv = iv; this.token_key = token_key; this.token_secret = token_secret; this.user = u; } @Override public String toString() { return "DropboxAuthentication [type=" + type + ", token_key=" + token_key + ", token_secret=" + token_secret + ", count=" + count + ", crawled=" + crawled + ", cipher=" + Arrays.toString(cipher) + ", iv=" + Arrays.toString(iv) + ", lastCrawlTime=" + lastCrawlTime + ", user=" + user + "]"; } } </code></pre> <p>I suppose that there is a problem with transactions, I tried to do</p> <pre><code>JPA.em().getTransaction().commit(); </code></pre> <p>but I gives me another exception that the transaction is not activated. Suprisingly </p> <pre><code>JPA.em().getTransaction().begin(); JPA.em().getTransaction().commit(); </code></pre> <p>throws an exception that there is already a transaction running.</p> <p>So probably the main question is how play handles transactions in test mode</p> <p>play framework: 1.2.3</p> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em></strong> UPDATE <strong></em>**<em>*</em>**<em>*</em>**<em>*</em>****</strong> </p> <p>I changed my application.conf from</p> <pre><code>%db=mem </code></pre> <p>to</p> <pre><code>%test.db=mysql://USER:PASSWORD@localhost/development </code></pre> <p>In the following I get a different exception (at the same line as before) now:</p> <pre><code>javax.persistence.EntityNotFoundException: Unable to find models.User with id 1 at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:133) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233) at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090) at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630) at org.hibernate.type.EntityType.resolve(EntityType.java:438) at org.hibernate.type.EntityType.replace(EntityType.java:298) at org.hibernate.type.AbstractType.replace(AbstractType.java:176) at org.hibernate.type.TypeHelper.replace(TypeHelper.java:212) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:600) at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:337) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686) at play.db.jpa.GenericModel.merge(GenericModel.java:211) at mashpan.crawl.jobs.UpdateDropboxRowJob.doJob(UpdateDropboxRowJob.java:33) at play.jobs.Job.doJobWithResult(Job.java:50) at play.jobs.Job.call(Job.java:146) </code></pre> <p>However, looking in the db I see that the user is actually persisted there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload