All OneToMany references being deleted upon update
by Robert Campbell
I've been using JPA w/Hibernate 3.4.0.GA for a long time now, and I
never experienced this behavior before:
I have a couple OneToMany relationships in a couple Embeddable
classes. When I update any of these relationships, either by removing
a member or even changing a field in the member, randomly the entire
cross reference table is cleared for that entire Entity.
Let me be more specific:
I have a "User" Entity with a "Foo" Embeddable reference. This "Foo"
class also has a "Bar" Embeddable reference. Foo has a
OneToMany(Cascade.ALL) Set<Baz> and Bar has two OneToMany(Cascade.ALL
minus DELETE) Set<Baz>. Hibernate has created a "user_baz" cross
reference table to store the user_id x baz_id relationship.
I have a Transactional method which loads the User via the
EntityManager, then performs some update on one of the Baz objects,
either updated a field or removing it from the collection. It actually
looks like this:
@Transactional
public void removeBaz(final Long userId, final Long bazId) {
final User user = getUserById(userId);
user.removeBaz(bazId);
}
Mostly this works as desired, with the Baz in question being marked as
deleted or having the reference actually deleted (I've played
w/different versions). Sometimes, however, the entire "user_baz" cross
reference table for that user will get wiped out. Even if I have 20
references in each of the three Sets, all of them just disappear from
the table. The actual Baz records in the baz table remain.
I've traced the code line by line, and the user code (stuff I wrote)
is all functioning properly. In other words, all three collections
(and their contents) appear correct after "user.removeBaz(bazId);"
returns. Clearly something is wrong.
Any ideas what the problem might be? Any hints for debugging this?
Rob
14 years, 7 months
org.hibernate.HibernateException: Error while accessing enum.values(): class com.mksoft.fbautomate.domain.Account$Type
by Misha Koshelev
This error is driving me nuts!!!
Caused by: java.lang.NoSuchMethodException:
com.mksoft.fbautomate.domain.Account$Type.values()
The same exact class works fine in a separate Groovy file.
Any ideas/help much appreciated.
Most confusing...
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html
has no values() method!
Here is my class:
@Entity class Account {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long id
enum Type {MYVALUE}
@Enumerated(EnumType.STRING)
public Type type
public String email
// @org.hibernate.annotations.Type(type="encryptedString")
public String pass
public String fullName
String toString() { "type:\""+type+"\",email:\""+email
+"\""+",fullName=\""+fullName+"\"" }
}
Thank you!
Misha
p.s. for the record if I move the enum _outside_ the entity class like
enum type {MYVALUE}
@Entity class Account {
...
}
all is fine. Any ideas??? Thank you. I am using Gradle.
14 years, 8 months
@UniqueConstraint with @ManyToOne field???
by Misha Koshelev
Dear All:
Thank you for a great product!
Using the following code:
@Entity
@Table(uniqueConstraints=[@UniqueConstraint(columnNames=["account","name"])])
class Friend {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long id
@ManyToOne
public Account account
public String href
public String name
}
I get the following error:
org.hibernate.AnnotationException: Unable to create unique key
constraint (account, name) on table Friend: account not found
It seems this has to do with the @ManyToOne constraint, which I imagine
actually creates a separate UniqueConstraint???
In any case, if I take this out, there is no complaint about the
UniqueConstraint, but there is another error which makes me believe it
must be left in.
org.hibernate.MappingException: Could not determine type for:
com.mksoft.fbautomate.domain.Account, at table: Friend, for columns:
[org.hibernate.mapping.Column(account)]
Any hints how I can create such a desired constraint (i.e., that each
combination of account and name occurs only once???)
Thank you!
Misha
14 years, 8 months
Unable to configure EntityManagerFactory with cause: invalid constant type: 60
by Kaleb Pederson
I'm creating a cli tool to manage an existing application. Both the
application and the tests build fine and run fine but despite that I
receive a javassist failure when running my cli tool. I can run the
application successfully within Eclipse (Right click->Run As->Java
Application), but using the maven-generated jar-with-dependencies
fails. I presume the difference is that with Eclipse javassist isn't
inspecting the containing jar, rather, it's inspecting all of the
class files (and perhaps a few dependent 3rd-party jars). I've tried
with both hibernate 3.4 and 3.5.1-Final (since 3.5.2-Final isn't yet
in the maven repository) and get the exact same error.
Here's the stack trace:
INFO: Bytecode provider name : javassist
...
INFO: Hibernate EntityManager 3.5.1-Final
Exception in thread "main" javax.persistence.PersistenceException:
Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
...
at com.sophware.flexipol.admin.AdminTool.<init>(AdminTool.java:40)
at com.sophware.flexipol.admin.AdminTool.main(AdminTool.java:69)
Caused by: java.lang.RuntimeException: Error while reading
file:flexipol-jar-with-dependencies.jar
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:131)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:457)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:347)
... 11 more
Caused by: java.io.IOException: invalid constant type: 60
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:693)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243)
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209)
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170)
at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:119)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146)
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128)
... 14 more
Since I know the jar is fine as the unit and integration tests run
against it, I thought it might be a problem with javassist, so I tried
cglib. The bytecode provider then shows as cglib but I still get the
exact same stack trace with javassist present in it.
cglib is definitely in the classpath:
$ unzip -l flexipol-jar-with-dependencies.jar | grep cglib | wc -l
383
Is this a problem with javassist or something related to my hibernate
configuration? Any ideas how I can track it down?
Thank you for the help.
--
Kaleb Pederson
Blog - http://kalebpederson.com
Twitter - http://twitter.com/kalebpederson
14 years, 8 months
sql error with criteria query
by Genís Pujol
Hello list,
I'm getting the following error:
SQLGrammarException: select this_.territorioCodigo as y0_,
this_.perfilId as y1_ from UsuarioTerritorioPerfilId this_ where
this_.usuarioId=?
when using the following query:
List utpList = session.createCriteria(UsuarioTerritorioPerfilId.class).setProjection(
Projections.projectionList()
.add(Projections.property("territorioCodigo"))
.add(Projections.property("perfilId"))
).add(Restrictions.eq("usuarioId",id)).list();
}catch (SQLGrammarException e) {
this.setMsg("Criteria error: No s'han pogut obtenir les dades: " + e.getSQL());
return msg;
}
You can check the full code here: http://dpaste.com/202714/ (mapped java
class) and here http://dpaste.com/202716/ (function making the query).
Any tips will be appreciated :)
Regards,
Genis
14 years, 8 months
Batch update returned unexpected row count from update
by Douglas Ferguson
Hi,
I see this from time to time and although the message seems obvious, I'm a bit perplexed as to how this could happen. Are there any potential things I should be considering when I see this?
D/
<span style="visibility: hidden;" wicketpath="form_hiddenStackTrace">org.hibernate.StaleStateException:Batch update returned unexpected row count from update [1]; actual row count: 0; expected: 1 org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
14 years, 8 months