[Hibernate-JIRA] Created: (ANN-654) Generated SQL includes a column named "null" when referencing a map entry by key and using @LazyCollection(LazyCollectionOption.EXTRA)
by Paul Roe (JIRA)
Generated SQL includes a column named "null" when referencing a map entry by key and using @LazyCollection(LazyCollectionOption.EXTRA)
--------------------------------------------------------------------------------------------------------------------------------------
Key: ANN-654
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-654
Project: Hibernate Annotations
Issue Type: Bug
Components: binder
Affects Versions: 3.2.0.ga
Environment: Oracle 10g, hibernate 3.2
Reporter: Paul Roe
We have an Product entity with a map of RegionProduct by Region.
@MapKey(name="region")
@OneToMany(mappedBy="product", targetEntity= RegionProductImpl.class, fetch = FetchType.LAZY)
@LazyCollection(LazyCollectionOption.EXTRA)
private Map<Region, RegionProduct> regionProducts = new HashMap<Region, RegionProduct>();
When accessing an element of the map by key, the SQL that is generated includes a "null" column in the WHERE condition.
where regionprod0_.PROD_ID=? and regionprod0_.null=?
resulting in the stack trace
org.hibernate.exception.SQLGrammarException: could not collection element by index
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1841)
at org.hibernate.loader.entity.CollectionElementLoader.loadElement(CollectionElementLoader.java:72)
at org.hibernate.persister.collection.OneToManyPersister.getElementByIndex(OneToManyPersister.java:360)
at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:158)
at org.hibernate.collection.PersistentMap.get(PersistentMap.java:146)
Iterating over the collection works successfully, but populates the entire collection, which is what Extra-Lazy is meant to avoid.
--
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
12 years, 1 month
[Hibernate-JIRA] Created: (HHH-3854) Issue with greedy loading of associations (default-lazy=false )
by Amar Singh (JIRA)
Issue with greedy loading of associations (default-lazy=false )
---------------------------------------------------------------
Key: HHH-3854
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3854
Project: Hibernate Core
Issue Type: Bug
Components: envers
Environment: Hibernate - core 3.4.0-SNAPSHOT, Hibernate-envers (from trunk)
Reporter: Amar Singh
Attachments: greedy-loading.zip
I have an Entity GP which has a many to one association to entity CA.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.envers.test.integration.onetoone.bidirectional" default-lazy="false">
<class name="BidirectionalRefIngPK" table="BIDIRECTIONAL_REFERENCING_ENTITY">
<id name="id" type="long" column="BIDIRECTIONAL_REFERENCING_ID" >
<generator class="native"/>
</id>
<property name="data"/>
<many-to-one name="reference" cascade="save-update" class="BidirectionalRefEdPK" column="BIDIRECTIONAL_REFERENCED_ID"/>
</class>
<class name="BidirectionalRefEdPK" table="BIDIRECTIONAL_REFERENCED_ENTITY">
<id name="longId" type="long" column="BIDIRECTIONAL_REFERENCED_ID">
<generator class="native"/>
</id>
<property name="data"/>
</class>
</hibernate-mapping>
With this when I load a previous version of BidirectionalRefIngPK, the loading mechanism tries to create a proxy for BidirectionalRefEdPK, but in my case lazy is false so an internal call to createProxy will return NULL hence .
This happens in ToOneIdMapper.java in method mapToEntityFromMap around line 82, which then internally calls for AbstractEntityTuplizer.java line 395 for getProxyFactory() ending in NULL pointer exception because proxy factory is null as mine is a greedy loading.
TO REPRODUCE
~~~~~~~~~~~~~
Please find a zipped folder attached. The zipped file has 4 files:
- GreedyLoading.java (actual testng test case)
- BidirectionalRefEdPK.java (Entity 1)
- BidirectionalRefIngPK.java (Entity 2)
- greedyloading.hbm.xml
Please place the three java files in its package (org.hibernate.envers.test.integration.onetoone.bidirectional), couldn't find the right package so created test case accordingly. Put the greedyloading.hbm.xml in src/test/resources.
Now when testng runs GreedyLoading.java you should see NPE.
--
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
12 years, 1 month
[Hibernate-JIRA] Created: (HHH-2891) Query cache fails on many-to-many select
by Oleg Efimov (JIRA)
Query cache fails on many-to-many select
----------------------------------------
Key: HHH-2891
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2891
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.5
Reporter: Oleg Efimov
I have two entities, User and Group, with many-to-many relation:
-------------------------------------------------------------------------------------------------- User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test.hibernate">
<class name="User" table="`USER`">
<id name="id" type="long" unsaved-value="null">
<column name="USER_ID" not-null="true"/>
<generator class="native"/>
</id>
<property name="login">
<column name="LOGIN" not-null="true" length="255"/>
</property>
<bag name="groups" table="USER_GROUP" lazy="false" cascade="none">
<key column="USER_ID"/>
<many-to-many class="Group" column="GROUP_ID"/>
</bag>
</class>
</hibernate-mapping>
-------------------------------------------------------------------------------------------------- Group.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test.hibernate">
<class name="Group" table="`GROUP`">
<id name="id" type="long" unsaved-value="null">
<column name="GROUP_ID" not-null="true"/>
<generator class="native"/>
</id>
<property name="name">
<column name="GROUPNAME" not-null="true" length="100"/>
</property>
<bag name="users" table="USER_GROUP" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="GROUP_ID"/>
<many-to-many class="User" column="USER_ID"/>
</bag>
</class>
<query name="Group.select.by.login" cacheable="true"><![CDATA[
select user.groups from User user where user.login=?
]]>
</query>
</hibernate-mapping>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test.hibernate.User and test.hibernate.Group classes are just simple beans.
In Group.hbm.xml there is a query called "Group.select.by.login", it's intended to be cached. So I add corresponding properties to Hibernate configuraition:
--------------------------------------------------------------------------------------------------
properties.put("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider");
properties.put("hibernate.cache.use_query_cache", "true");
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Configuration has no extra parameters.
Then I'm trying to execute the query two times:
-------------------------------------------------------------------------------------------------- test fragment
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = null;
try {
session = sessionFactory.openSession();
Query query = session.getNamedQuery("Group.select.by.login");
List<Group> groups;
groups = query.setParameter(0, "admin").list(); // +++++++++++++++This list() returns list of two Group objects, ok +++++++++++++++
System.out.println("-----------------------------------------------------------------------------------");
for (Group group : groups) {
System.out.println(group.getName());
}
System.out.println("-----------------------------------------------------------------------------------");
groups = query.setParameter(0, "admin").list(); // +++++++++++++++This list() returns list of two nulls +++++++++++++++
System.out.println("-----------------------------------------------------------------------------------");
for (Group group : groups) {
System.out.println(group.getName());
}
System.out.println("-----------------------------------------------------------------------------------");
} finally {
if (session != null) {
session.close();
}
sessionFactory.close();
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The first query returns list of, in my case, two groups. The second query returns list of two nulls instead of the same list.
I've investigated the problem, and found the following:
Query return value is "user.groups", and during query analysis (org.hibernate.hql.ast.QueryTranslatorImpl:160) query return type is defined as "org.hibernate.type.BagType(test.hibernate.User.groups)". This seems to be the problem, as during query put operation org.hibernate.CollectionType.disassemble is called (org.hibernate.cache.StandardQueryCache:80), which simply returns null as owner is null.
If this query is not a misuse, then I think, something is to be done at the time of analysis, so that return type be somewhat different.
Thanks.
--
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
12 years, 1 month
[Hibernate-JIRA] Created: (HHH-3795) Unexpected behaviour of saveOrUpdate() for associations with delete-orphan
by Fabian Dankof (JIRA)
Unexpected behaviour of saveOrUpdate() for associations with delete-orphan
--------------------------------------------------------------------------
Key: HHH-3795
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3795
Project: Hibernate Core
Issue Type: Improvement
Environment: Hibernate 3.2.6.GA, PostgreSQL 8.3
Reporter: Fabian Dankof
Hello there,
I think saveOrUpdate() behaves somewhat unexpected for associations with delete-orphan cascading style:
Prerequisite: Association is set to cascade="all,delete-orphan" and nullable=true
1) Within a single session (i.e. a transient object):
* Load parent
* Delete child
* saveOrUpdate()
Result: Child is deleted from DB, a DELETE statement was issued
2) Across multiple session (i.e. a detached object):
* Have parent with valid ID, but empty list/set of children
* saveOrUpdate()
Result: Child is not deleted from DB, an UPDATE statement is issued which sets FK of child to 'null'
3) like 2) but nullable is FALSE
Result: Nothing happens.
With merge() everything works as expected for detached and transient instances. I would either expect saveOrUpdate() to
completely disregard DELETE statements OR behave similar to merge(). At least the different results of case 1) and 2)
are pretty confusing.
Best regards,
Fabian
--
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
12 years, 1 month