[Hibernate-JIRA] Created: (ANN-723) Impossible to bind a SortedMap collection
by Alexandre Dutra (JIRA)
Impossible to bind a SortedMap collection
-----------------------------------------
Key: ANN-723
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-723
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.0.ga
Environment: hibernate: 3.2.5.ga
hibernate-annotations: 3.3.0.ga
database: HSQL 1.8.0.7
Reporter: Alexandre Dutra
Priority: Minor
See http://forum.hibernate.org/viewtopic.php?t=976437
I have the following collection declared in a persistent class:
@CollectionOfElements
@Sort(type = SortType.NATURAL)
@JoinTable(name = "delivery_option_price", joinColumns = @JoinColumn(name = "delivery_option_id"))
private SortedMap<Float, MonetaryAmount> prices = new TreeMap<Float, MonetaryAmount>();
Hibernate fails to bind it to a database table. The stack trace is:
java.lang.NullPointerException
at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:129)
at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:53)
at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:83)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
...
A workaround to this is to explicitly specify the map key class by adding a org.hibernate.annotations.MapKey annotation:
@org.hibernate.annotations.MapKey(targetElement = Float.class, columns = @Column(name = "WEIGHT"))
Browsing the source code, I realized that the NullPointerException is being raised beacause the following method returns null in org.hibernate.annotations.common.reflection.java.JavaXCollectionType:
public XClass getMapKey() {
return new TypeSwitch<XClass>() {
@Override
public XClass caseParameterizedType(ParameterizedType parameterizedType) {
if ( getCollectionClass().isAssignableFrom( Map.class ) ) {
return toXClass( parameterizedType.getActualTypeArguments()[0] );
}
return null;
}
}.doSwitch( approximate() );
}
More specifically, the following expression seems misconstructed:
getCollectionClass().isAssignableFrom( Map.class )
The correct expression would be:
Map.class.isAssignableFrom( getCollectionClass() )
At least if, as I understand it, the goal is to determine whether the collection class is or is not a Map in anyone one of its implementations. The same applies to the getElementClass() method, in the same class.
If my analyzis is correct, the bug might be very easy to fix, but maybe I'm underestimating its impacts.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 7 months
[Hibernate-JIRA] Created: (HV-53) AssertTrue and AssertFalse not compatible with null values
by benoit heinrich (JIRA)
AssertTrue and AssertFalse not compatible with null values
----------------------------------------------------------
Key: HV-53
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-53
Project: Hibernate Validator
Issue Type: Bug
Components: validators
Affects Versions: 3.0.0.ga
Reporter: benoit heinrich
The AssertTrue and AssertFalse validators do not work with null values, they actually generate a NullPointerException.
The code fix for this should be:
public class AssertFalseValidator implements Validator<AssertFalse>, Serializable {
public boolean isValid(Object value) {
if (value == null) return true; << this is the fix
return !(Boolean) value;
}
public void initialize(AssertFalse parameters) {
}
}
public class AssertTrueValidator implements Validator<AssertTrue>, Serializable {
public boolean isValid(Object value) {
if (value == null) return true; << this is the fix
return (Boolean) value;
}
public void initialize(AssertTrue parameters) {
}
}
Cheers,
/Benoit
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 7 months
[Hibernate-JIRA] Created: (HHH-3199) Some query fail in BinaryLogicOperatorNode.mutateRowValueConstructorSyntaxesIfNecessary when there is a one-to-one bidi relation.
by Benjamin Lerman (JIRA)
Some query fail in BinaryLogicOperatorNode.mutateRowValueConstructorSyntaxesIfNecessary when there is a one-to-one bidi relation.
---------------------------------------------------------------------------------------------------------------------------------
Key: HHH-3199
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3199
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: Hibernate version 3.2.6.ga. Database postgreSQL,
Reporter: Benjamin Lerman
Attachments: example.zip
When mapping a one-to-one bidi relation with the following mappings :
<hibernate-mapping>
<class lazy="true" name="com.genia.toolbox.model.association.one_to_one_bidi.impl.DriverOneToOneBidiImpl" proxy="com.genia.toolbox.model.association.one_to_one_bidi.DriverOneToOneBidi" table="_driver_one_to_one_bidi">
<id name="identifier" column="_identifier" type="java.lang.Long" unsaved-value="null">
<generator class="hilo"><param name="table">_hibernate_unique_key_169</param></generator>
</id>
<one-to-one cascade="persist,merge,save-update" class="com.genia.toolbox.model.association.one_to_one_bidi.impl.CarOneToOneBidiImpl" name="carInternal" property-ref="driverInternal"/>
</class>
</hibernate-mapping>
and
<hibernate-mapping>
<class lazy="true" name="com.genia.toolbox.model.association.one_to_one_bidi.impl.CarOneToOneBidiImpl" proxy="com.genia.toolbox.model.association.one_to_one_bidi.CarOneToOneBidi" table="_car_one_to_one_bidi">
<id name="identifier" column="_identifier" type="java.lang.Long" unsaved-value="null">
<generator class="hilo"><param name="table">_hibernate_unique_key_181</param></generator>
</id>
<many-to-one cascade="persist,merge,save-update" class="com.genia.toolbox.model.association.one_to_one_bidi.impl.DriverOneToOneBidiImpl" name="driverInternal" column="_driver" unique="true"/>
</class>
</hibernate-mapping>
the following query:
FROM com.genia.toolbox.model.association.one_to_one_bidi.DriverOneToOneBidi AS a2, com.genia.toolbox.model.association.one_to_one_bidi.CarOneToOneBidi AS a3 WHERE ((a2.carInternal)=(a3))
failed with an exception:
left and right hand sides of a binary logic operator were incompatibile
This is due to the call to the method mutateRowValueConstructorSyntaxesIfNecessary of BinaryLogicOperatorNode.
One of the type is a OneToOneType which returns 0 for getColumnSpan while the other is a ManyToOneType that returns 1. The two values are not equal and an exception is thrown.
I join to this issue the relevant classes and mappings.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 7 months
[Hibernate-JIRA] Created: (HHH-3152) StaleStateException using many-to-many together with one-to-many
by Donatas Ciuksys (JIRA)
StaleStateException using many-to-many together with one-to-many
----------------------------------------------------------------
Key: HHH-3152
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3152
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Hibernate EntityManager 3.3.1 GA, Hibernate Annotations 3.3.0 GA, Hibernate Core 3.2.6 GA.
DB2 9.5 (production), Derby 10.3.2.1 (reproducible test case)
Reporter: Donatas Ciuksys
Attachments: db_schema.gif, ManyToMany.zip
I have many-to-many association between tables A and B (via join table A_B, see attached db_schema.gif). Join table has additional data columns, so I represent it as entity AB and have two one-to-many associations (A <-> AB and B <-> AB, with cascade=Cascade.REMOVE). Also I have many-to-many association between A and B (joinColumns are marked with insertable=false, updatable=false, though the marking/unmarking doesn't change the behaviour).
Table A is modeled as abstract entity A that is inherited by two concrete entities ATrue and AFalse. Table A has column BOOL_PROP (boolean property) of type INTEGER. ATrue spans objects with BOOL_PROP being true (1), AFalse - being false (0), column BOOL_PROP is used as Discriminator column.
The problem: having in database several ATrue and AFalse entities, it is impossible to delete ATrue entity - StaleStateException is being thrown:
Code fragment (p.getAllTrueA() return list of ATrue entities):
em.getTransaction().begin();
em.remove(p.getAllTrueA().get(0));
em.getTransaction().commit();
Log and exception stack trace:
Hibernate: delete from A_B where A=?
2008-03-03 18:02:10,313 [main] DEBUG org.hibernate.type.IntegerType - binding '4' to parameter: 1
Hibernate: delete from ADMIN.A_B where ID=?
2008-03-03 18:02:10,403 [main] DEBUG org.hibernate.type.IntegerType - binding '4' to parameter: 1
2008-03-03 18:02:10,473 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
...
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
at manytomany.Main.run(Main.java:30)
at manytomany.Main.main(Main.java:15)
Exception in thread "main" javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
at manytomany.Main.run(Main.java:30)
at manytomany.Main.main(Main.java:15)
Caused by: javax.persistence.OptimisticLockException: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:654)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:59)
... 2 more
Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
...
The problem is that after:
Hibernate: delete from A_B where A=?
following statement is being executed:
Hibernate: delete from ADMIN.A_B where ID=?
The first statement deletes child A_B rows belonging to parent A. The second tries to delete what is already deleted.
Why I think it is related to many-to-many association: if I comment many-to-many association fields and getters/setters, problem is gone.
Attached is Eclipse project (standard java application), Derby DDL scripts. Following steps are needed to reproduce the problem:
1. Adjust the classpath (specify correct path to Hibernate EntityManager and its dependencies, Derby 10.3 derbyclient.jar)
2. Adjust database URL in /src/META-INF/persistence.xml (I'm using absolute path to DB, that is located at the projects root)
3. Start Derby network server (or adjust database URL to use embedded driver)
4. Start the application - it tries to delete ATrue entity and fails.
You can recreated the database if you wish - projects root folder contains DB_DDL.sql scripts. The program checks, whether the DB is empty, and if so, first fills it up with test data, then exits. Restart it again - it will load some ATrue entities and will try to delete one.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 8 months