[Hibernate-JIRA] Created: (HHH-4009) idbag collection-id native / identity fails on sql server (but works on oracle)
by dominic roesti (JIRA)
idbag collection-id native / identity fails on sql server (but works on oracle)
-------------------------------------------------------------------------------
Key: HHH-4009
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4009
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.4
Environment: - jboss 4.3.0_GA coming with hibernate 3.2.4
- java jdk 1.5.0_18
- windows server 2008 E SP2
- microsoft sqljdbc 2.0 driver
- microsoft sql server 2008 E
Reporter: dominic roesti
related forum post:
https://forum.hibernate.org/viewtopic.php?f=1&t=998004&start=0
i'm trying use native id generation to enable my hibernate / java application for cross platform usage, it should run with oracle 10g (sequence) as well as with microsoft sql server 2008 (identity)
i'm having a class "RoutingTable" with class "Route" as composite element, configured as follows:
/**
* @hibernate.collection-id generator-class = "native" type =
* "java.lang.Long" column = "ID"
* @hibernate.composite-element class = "com.rixxo.mbsp.model.routing.Route"
*
* @hibernate.generator-param
* name = "sequence"
* value = "sq_id_mbsp_route"
*
* @hibernate.idbag lazy = "false" table = "MBSP_ROUTE" order-by = "POSITION
* asc"
* @hibernate.key column = "ROUTING_TABLE_ID"
*/
public List<Route> getRoutes() {
return routes;
}
public void setRoutes(List<Route> routes) {
this.routes = routes;
}
on sql server, when saving the RoutingTable with new Routes on, this causes a classcast exception:
Code:
2009-07-02 10:18:26,369 [http-8443-3] INFO STDOUT - Hibernate: insert into MBSP_ROUTE (ROUTING_TABLE_ID, ID, OPERATOR_ID, CHANNEL_ID, POSITION) values (?, ?, ?, ?, ?)
2009-07-02 10:18:26,370 [http-8443-3] INFO LongType - could not bind value 'POST_INSERT_INDICATOR' to parameter: 2; org.hibernate.id.IdentifierGeneratorFactory$2
2009-07-02 10:18:26,371 [http-8443-3] WARN arjLoggerI18N - [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1b853a5
java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorFactory$2
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:807)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1359)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:56)
i tried "native" as well as "identity" with the same result.
there are multiple problems:
1) hibernate seems to try to insert a value into an identity field (ID)
2) the POST_INSERT_INDICATOR value cant be bound
--
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
15 years, 5 months
[Hibernate-JIRA] Created: (HHH-3813) Automatic flush to the join table before a criteria query
by Maxim Gordienko (JIRA)
Automatic flush to the join table before a criteria query
---------------------------------------------------------
Key: HHH-3813
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3813
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: Hibernate Core 3.3.1.GA, H2 1.1.108
Reporter: Maxim Gordienko
Attachments: criteriaflush.zip
With the default flush mode Hibernate flushes query regions before queries to run SQL against actual table data.
If two entity are connected using the join table and data is queried using a criteria Hibernate does not flush to the join table.
It flushes to the entity tables though.
The attached test case produces the SQL output
Hibernate: insert into USERS (ID, NAME) values (null, ?)
Hibernate: insert into ITEMS (ID, NAME) values (null, ?)
Hibernate: select this_.ID as ID0_1_, this_.NAME as NAME0_1_, items3_.USER_ID as USER1_, items1_.ID as ITEM2_, items1_.ID as ID2_0_, items1_.NAME as NAME2_0_ from USERS this_ inner join USER_ITEMS items3_ on this_.ID=items3_.USER_ID inner join ITEMS items1_ on items3_.ITEM_ID=items1_.ID where items1_.NAME=?
But it should flush to the USER_ITEMS table before executing the criteria query.
The commented HQL query does flush to both the entity tables and the join table.
The problem is in the org.hibernate.loader.criteria.CriteriaQueryTranslator.getQuerySpaces() method.
It returns only the entity tables.
--
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
15 years, 5 months
[Hibernate-JIRA] Created: (HHH-4018) ClassCastException with EntityMode.DOM4J in case of object as index
by Renat Valeev (JIRA)
ClassCastException with EntityMode.DOM4J in case of object as index
-------------------------------------------------------------------
Key: HHH-4018
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4018
Project: Hibernate Core
Issue Type: Bug
Environment: Hibernate 3.2.6.ga, HSQLDB
Reporter: Renat Valeev
public class TestA {
private Map testMap = new HashMap<TestIndex, TestElement>();
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Map getTestMap() {
return testMap;
}
public void setTestMap(Map testMap) {
this.testMap = testMap;
}
}
public class TestIndex {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
public class TestElement {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
--------------
Mappings
--------------
<hibernate-mapping default-lazy="true">
<class name="TestA" node="TestA">
<id name="id" type="integer" column="id" node="@id">
<generator class="increment" />
</id>
<map name="testMap" cascade="all" embed-xml="true" node="testMap">
<key column="parent_id" />
<map-key-many-to-many column="index_id" class="TestIndex"/>
<many-to-many column="element_id" class="TestElement" embed-xml="true" node="test_element" />
</map>
</class>
<class name="TestIndex" node="TestIndex">
<id name="id" type="integer" column="id" node="@id">
<generator class="increment" />
</id>
</class>
<class name="TestElement" node="TestElement">
<id name="id" type="integer" column="id" node="@id">
<generator class="increment" />
</id>
</class>
</hibernate-mapping>
--------------
Test class
--------------
public class test extends AbstractTransactionalJUnit38SpringContextTests{
@Autowired
private SessionFactory _sessionFactory;
@Test
@Transactional
public void testTest(){
Session dom4jSession = _sessionFactory.getCurrentSession().getSession(EntityMode.DOM4J);
List result = dom4jSession.createCriteria(TestA.class).list(); // EXCEPTION RAISES HERE
for (int i = 0; i < result.size(); i++) {
Element node = (Element) result.get(i);
System.out.println(node);
}
}
@Transactional
@Override
public void setUp() throws Exception{
TestIndex ti = new TestIndex();
TestElement te = new TestElement();
_sessionFactory.getCurrentSession().saveOrUpdate(ti);
_sessionFactory.getCurrentSession().saveOrUpdate(te);
TestA t = new TestA();
HashMap<TestIndex,TestElement> hm = new HashMap<TestIndex,TestElement>();
hm.put(ti, te);
t.setTestMap(hm);
_sessionFactory.getCurrentSession().saveOrUpdate(t);
_sessionFactory.getCurrentSession().flush();
}
}
java.lang.ClassCastException: org.hibernate.type.ManyToOneType cannot be cast to org.hibernate.type.NullableType
at org.hibernate.collection.PersistentIndexedElementHolder.readFrom(PersistentIndexedElementHolder.java:144)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.type.CollectionType.getCollection(CollectionType.java:613)
at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:408)
at org.hibernate.type.CollectionType.resolve(CollectionType.java:402)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:120)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at testTest(test.java:34)
--
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
15 years, 5 months
[Hibernate-JIRA] Created: (HHH-4014) One-to-one: property-ref: foreign key: composite-id
by Sandeep Vaid (JIRA)
One-to-one: property-ref: foreign key: composite-id
---------------------------------------------------
Key: HHH-4014
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4014
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.2, 3.3.1, 3.3.0.SP1, 3.3.0.GA, 3.3.0.CR2, 3.3.0.CR1, 3.2.7, 3.2.6, 3.2.5, 3.2.4.sp1, 3.2.4, 3.2.3, 3.2.2, 3.2.1
Environment: Hibernate Version 3.2.6, Database Db2
Reporter: Sandeep Vaid
Priority: Blocker
Presently there is no way in hibernate using which we can specify one-to-one relationship with property-ref to part of composite-id
of another entity. The following scenario will clarify the above statement.
There is a one-to-one relationship between Product and ProductBasic.
Product -----> productId (PK)
ProductBasic ----> pId, useCode, StartTime (as composite key) and pId is also foreign key referencing Product.
This is a legacy database. We get one-to-one relationship by using the condition:
Product.productId=ProductBasic.pId and useCode='008' and startTime<currentTime<endTime.
In Product.hbm.xml:
<one-to-one name="productBasic" cascade="save-update" property-ref="activeProduct" constrained="true">
<formula>PRODUCTID</formula>
</one-to-one>
In ProductBasic.hbm.xml
<composite-id name="compProductBasic">
<key-property name="pId" column="PID" ></key-property>
<key-property name="useCode" column="USECODE" "></key-property>
<key-property name="startTime" column="STARTTIME" ></key-property>
</composite-id>
<properties name="activeProduct">
<property name="compProductBasic.pId" class="Product" insert="false" update="false" lazy="proxy" />
</properties>
If my relationship is Product.productId = ProductBasic.pId, there is no way in hibernate to specify this relationship.
Moreover we cannot remap(refer to) the property of composite-id (compProductBasic.pId in current example)..
Hence i request for enhancement in hibernate to incorporate this.
--
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
15 years, 5 months