[Hibernate-JIRA] Created: (HHH-2501) Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.
by Gunther Schadow (JIRA)
Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.
----------------------------------------------------------------------------------------------
Key: HHH-2501
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2501
Project: Hibernate3
Type: Improvement
Components: core
Environment: any
Reporter: Gunther Schadow
ISSUE:
Given an Entity entity and after Session.setReadOnly(entity), if the entity has lazy collections, lazy properties etc., other Entities are loaded into the Session upon navigating the object graph in the default read-writable state. However, it seems more reasonable to maintain the read-only state of the owning object.
REQUEST:
Ability to propagate read-only state of an entity in a session into other lazy-loaded entities.
BACKGROUND:
We have a system which permits users to make concurrent transactions which involve many of the same objects. Usually no changes happen on these shared objects, but instead connections (links) are made between these objects and new objects. For example, say you have an online meeting system, and every Meeting held has a link to a number of User object. The User objects are never changed in a Meeting, but there is a Relation called Participation (of User in Meeting) to which new relationships are added. When a new meeting is saved, it wants to save the User objects simply because a new Participation link entry was added to the collection.
To an extent we can prevent this from happening by setting the Users explicitly to read-only. However, now suppose we added a function "Invite your Friends" to a Meeting, in which we would simply go:
for(User friend : currentUser.getFriends())
meeting.addInvitation(friend);
Now an Invitation is like a Participation, and would be added into the User but now it wants to save these users just for a version upgrade only because they have received an Invitation.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HBX-1074) DelegatingReverseEngineeringStratey.columnToHibernateTypeName reports invalid values
by Joel Schuster (JIRA)
DelegatingReverseEngineeringStratey.columnToHibernateTypeName reports invalid values
------------------------------------------------------------------------------------
Key: HBX-1074
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1074
Project: Hibernate Tools
Issue Type: Improvement
Components: reverse-engineer
Affects Versions: 3.2.1
Environment: MyEclipse w/ Hibernate rev engineering against Oracle 10g
Reporter: Joel Schuster
When implementing an extention to the [u]DelegatingReverseEngineeringStrategy [/u]the [u]columnToHibernateTypeName [/u]does not report the true value of the [b]precision [/b]and [b]scale [/b]column of the table description/definition.
The method signature:
[code]@Override
public String columnToHibernateTypeName( TableIdentifier table, String columnName, int sqlType,
int length, int precision, int scale, boolean nullable,
boolean generatedIdentifier) {[/code]
The precision and scale parameters are [b]int[/b]. If the values in the definition are [b]null[/b] the values reported here come out as DATA_LENGTH and 0. Not null.
These parameters should be [b]Integer[/b] and be set to [b]null [/b]when applicable.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HHH-2094) Hibernate is ignoring native sql aliases and generating "column not found" error
by Leonardo Penczek (JIRA)
Hibernate is ignoring native sql aliases and generating "column not found" error
--------------------------------------------------------------------------------
Key: HHH-2094
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2094
Project: Hibernate3
Type: Bug
Components: query-sql
Versions: 3.2.0.cr4
Environment: 3.2.0.cr4, Adaptive Server Enterprise/12.5.3
Reporter: Leonardo Penczek
Priority: Critical
As simples as that:
1: Query q = em.createNativeQuery("select cd_person as codePerson, cd_person as identif from PERSON");
2: List<Object[]> resultList = (List<Object[]>) q.getResultList();
Hibernate is ignoring my aliases when retrieving information from the ResultSet because it is trying to retrieve by column name, generating the following error:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:641)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
at <my line 2 in the code above>
...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
...
Caused by: java.sql.SQLException: S0022: Invalid column name 'cd_person'.
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseError(Unknown Source)
at com.sybase.jdbc3.tds.TdsResultSet.findColumnByLabel(Unknown Source)
at com.sybase.jdbc3.jdbc.SybResultSet.findColumn(Unknown Source)
at com.sybase.jdbc3.jdbc.SybResultSet.getInt(Unknown Source)
at org.jboss.resource.adapter.jdbc.WrappedResultSet.getInt(WrappedResultSet.java:690)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:594)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
Awesome! The SQL query runs, but the Hibernate try to get the column by the original name, not by the alias, causing the error!
It is not possible to correctly get the value of 2 different columns that have the same name!!!!
Hint: why Hibernate use ResultSet.get* by column name instead of positional ResultSet.get* (1, 2, 3,...)? It will solve this problem.
--
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
14 years, 11 months
[Hibernate-JIRA] Created: (HHH-3338) Order of attributes in generated SQL query is dependent on Java version
by Michael Gerz (JIRA)
Order of attributes in generated SQL query is dependent on Java version
-----------------------------------------------------------------------
Key: HHH-3338
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3338
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: WIndows XP, Java 5 Update 15, Java 6 update 5
Reporter: Michael Gerz
We use Hibernate Core 3.2.6 in combination with Derby 10.4.1.3.
When migrating from Java 5 to Java 6, we noticed a huge performance hit. Our analysis has unveiled that Hibernate 3.2.6 produces semantical identical but syntactically different queries for Java 5 and Java 6.
Java 5:
Hibernate: select logevent0_.ID as ID7_, logevent0_.INDEX_SENT as INDEX2_7_, logevent0_.TEST_RUN_ID as TEST3_7_, logevent0_.SENDER as SENDER7_, logevent0_.TIME_SENT as TIME5_7_, logevent0_.MESSAGE as MESSAGE8_, logevent0_.SEVERITY as SEVERITY8_, logevent0_.SERIALIZED_CONTENT as SERIALIZED1_11_, logevent0_.RECEIVER as RECEIVER11_, logevent0_.TIME_RECEIVED as TIME3_11_, logevent0_.INDEX_RECEIVED as INDEX4_11_, logevent0_.ACTION_REQUEST as ACTION1_13_, logevent0_.ACTION_REPLY as ACTION1_14_, logevent0_.clazz_ as clazz_ from ( select TEST_RUN_ID, SENDER, MESSAGE, SEVERITY, nullif('x','x') as SERIALIZED_CONTENT, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, nullif('x','x') as ACTION_REQUEST, TIME_SENT, nullif('x','x') as ACTION_REPLY, nullif('x','x') as RECEIVER, nullif(0,0) as INDEX_RECEIVED, INDEX_SENT, 2 as clazz_ from USER_LOG_EVENT union all select TEST_RUN_ID, SENDER, MESSAGE, SEVERITY, nullif('x','x') as SERIALIZED_CONTENT, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, nullif('x','x') as ACTION_REQUEST, TIME_SENT, nullif('x','x') as ACTION_REPLY, nullif('x','x') as RECEIVER, nullif(0,0) as INDEX_RECEIVED, INDEX_SENT, 3 as clazz_ from DEVEL_LOG_EVENT union all select TEST_RUN_ID, SENDER, nullif('x','x') as MESSAGE, nullif('x','x') as SEVERITY, nullif('x','x') as SERIALIZED_CONTENT, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, ACTION_REQUEST, TIME_SENT, nullif('x','x') as ACTION_REPLY, nullif('x','x') as RECEIVER, nullif(0,0) as INDEX_RECEIVED, INDEX_SENT, 6 as clazz_ from ACTION_REQUEST_LOG_EVENT union all select TEST_RUN_ID, SENDER, nullif('x','x') as MESSAGE, nullif('x','x') as SEVERITY, nullif('x','x') as SERIALIZED_CONTENT, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, nullif('x','x') as ACTION_REQUEST, TIME_SENT, ACTION_REPLY, nullif('x','x') as RECEIVER, nullif(0,0) as INDEX_RECEIVED, INDEX_SENT, 7 as clazz_ from ACTION_REPLY_LOG_EVENT union all select TEST_RUN_ID, SENDER, nullif('x','x') as MESSAGE, nullif('x','x') as SEVERITY, SERIALIZED_CONTENT, TIME_RECEIVED, ID, nullif('x','x') as ACTION_REQUEST, TIME_SENT, nullif('x','x') as ACTION_REPLY, RECEIVER, INDEX_RECEIVED, INDEX_SENT, 4 as clazz_ from DATA_FLOW_LOG_EVENT ) logevent0_ where logevent0_.TEST_RUN_ID=?
Java 6:
Hibernate: select logevent0_.ID as ID7_, logevent0_.INDEX_SENT as INDEX2_7_, logevent0_.TEST_RUN_ID as TEST3_7_, logevent0_.SENDER as SENDER7_, logevent0_.TIME_SENT as TIME5_7_, logevent0_.MESSAGE as MESSAGE8_, logevent0_.SEVERITY as SEVERITY8_, logevent0_.SERIALIZED_CONTENT as SERIALIZED1_11_, logevent0_.RECEIVER as RECEIVER11_, logevent0_.TIME_RECEIVED as TIME3_11_, logevent0_.INDEX_RECEIVED as INDEX4_11_, logevent0_.ACTION_REQUEST as ACTION1_13_, logevent0_.ACTION_REPLY as ACTION1_14_, logevent0_.clazz_ as clazz_ from ( select nullif('x','x') as RECEIVER, TIME_SENT, SEVERITY, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, SENDER, MESSAGE, TEST_RUN_ID, nullif('x','x') as SERIALIZED_CONTENT, INDEX_SENT, nullif(0,0) as INDEX_RECEIVED, nullif('x','x') as ACTION_REQUEST, nullif('x','x') as ACTION_REPLY, 2 as clazz_ from USER_LOG_EVENT union all select nullif('x','x') as RECEIVER, TIME_SENT, SEVERITY, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, SENDER, MESSAGE, TEST_RUN_ID, nullif('x','x') as SERIALIZED_CONTENT, INDEX_SENT, nullif(0,0) as INDEX_RECEIVED, nullif('x','x') as ACTION_REQUEST, nullif('x','x') as ACTION_REPLY, 3 as clazz_ from DEVEL_LOG_EVENT union all select nullif('x','x') as RECEIVER, TIME_SENT, nullif('x','x') as SEVERITY, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, SENDER, nullif('x','x') as MESSAGE, TEST_RUN_ID, nullif('x','x') as SERIALIZED_CONTENT, INDEX_SENT, nullif(0,0) as INDEX_RECEIVED, ACTION_REQUEST, nullif('x','x') as ACTION_REPLY, 6 as clazz_ from ACTION_REQUEST_LOG_EVENT union all select nullif('x','x') as RECEIVER, TIME_SENT, nullif('x','x') as SEVERITY, nullif('2000-1-1 00:00:00','2000-1-1 00:00:00') as TIME_RECEIVED, ID, SENDER, nullif('x','x') as MESSAGE, TEST_RUN_ID, nullif('x','x') as SERIALIZED_CONTENT, INDEX_SENT, nullif(0,0) as INDEX_RECEIVED, nullif('x','x') as ACTION_REQUEST, ACTION_REPLY, 7 as clazz_ from ACTION_REPLY_LOG_EVENT union all select RECEIVER, TIME_SENT, nullif('x','x') as SEVERITY, TIME_RECEIVED, ID, SENDER, nullif('x','x') as MESSAGE, TEST_RUN_ID, SERIALIZED_CONTENT, INDEX_SENT, INDEX_RECEIVED, nullif('x','x') as ACTION_REQUEST, nullif('x','x') as ACTION_REPLY, 4 as clazz_ from DATA_FLOW_LOG_EVENT ) logevent0_ where logevent0_.TEST_RUN_ID=?
The first order (using Java 5) looks more reasonable, because TEST_RUN_ID is the first column in all of the tables and it is also a foreign key.
The changed order of attributes does not really explain why Derby performs so poor on Java 6 and we have already issued a report to the Derby community.
Nevertheless, the SQL queries generated Hibernate should not depend on a specific version of Java. Maybe a compareTo() method is missing somewhere in the code...?
--
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
14 years, 12 months
[Hibernate-JIRA] Created: (HHH-2676) Cannot apply UPGRADE lock to scalar Query object
by John Wood (JIRA)
Cannot apply UPGRADE lock to scalar Query object
------------------------------------------------
Key: HHH-2676
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2676
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.1
Reporter: John Wood
Priority: Minor
Attachments: Bean.hbm.xml, Bean.java
If you try and add a lock to a Query object (against a named alias) when doing a scalar HQL query (e.g. "select sum(foo) from bah") then an error occurs.
The sample code (full working example is attached):
// Create query
Query q = session.createQuery("select b.value from Bean b");
// Set lock mode on query
q.setLockMode("b", LockMode.UPGRADE);
// Executre
q.list();
This causes the following error:
Exception in thread "main" java.lang.IllegalArgumentException: could not locate alias to apply lock mode : b
at org.hibernate.loader.hql.QueryLoader.applyLocks(QueryLoader.java:297)
at org.hibernate.loader.Loader.preprocessSQL(Loader.java:201)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
I have tried this both with an older version of Hibernate (3.1) and the latest with the same result (although the older Hibernate has the error message "alias not found".
I have attached a simple example to demonstrate this.
See also HHH-1965.
Perhaps, it is simply that one cannot lock scalar queries of this type. If so, then the fix would presumably be to include this in the Query class Javadocs.
--
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
14 years, 12 months
[Hibernate-JIRA] Created: (HSEARCH-248) Incorrect syntax near ', ' with org.hibernate.dialect.SQLServerDialect
by Isaac F (JIRA)
Incorrect syntax near ',' with org.hibernate.dialect.SQLServerDialect
---------------------------------------------------------------------
Key: HSEARCH-248
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-248
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.0.1.GA
Environment: Sql Server 2005, hibernate 3.2.6
Reporter: Isaac F
I get this exception when I make a createFullTextQuery with an Entity that have composite-id (I use TwoWayStringBridge impl to transform)
org.hibernate.util.JDBCExceptionReporter[main] - SQL Error: 102, SQLState: S0001
org.hibernate.util.JDBCExceptionReporter[main] - Incorrect syntax near ','.
A generated query is this:
/* criteria query */ select
this_.CE_CIF as CE1_0_0_,
this_.CE_FORMA_JURIDICA as CE2_0_0_,
this_.CE_DISCRIMINANTE as CE3_0_0_,
this_.CE_DELEGACION as CE4_0_0_,
from
CH_TERCEROS this_
where
(
(
this_.CE_CIF, this_.CE_FORMA_JURIDICA, this_.CE_DISCRIMINANTE, this_.CE_DELEGACION
) in (
(
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
), (
?, ?, ?, ?
)
)
)
but this syntax is not support by Sql Server 2005
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
14 years, 12 months
[Hibernate-JIRA] Created: (EJB-343) exception trying to load entity with idClass - 'id column not in any table'
by Adam Hardy (JIRA)
exception trying to load entity with idClass - 'id column not in any table'
---------------------------------------------------------------------------
Key: EJB-343
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-343
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Reporter: Adam Hardy
Hibernate EntityManager won't map an id-class for an entity. I have ust one entity with an inner class as the idClass.
Hibernate refuses to load the entity, throwing the following exception (see further down).
I am using hibernate-annotations-3.3.0ga and hibernate-entitymanager-3.3.1ga.
Mapping:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version="1.0">
<schema>DEV</schema>
<entity class="org.permacode.HabitatSpeciesLink" access="FIELD">
<table name="HABITAT_SPECIES_LINK" />
<id-class
class="org.permacode.HabitatSpeciesLink$HabitatSpeciesLinkId" />
<attributes>
<id name="habitatId">
<column name="HABITAT_ID" />
</id>
<id name="speciesId">
<column name="SPECIES_ID" />
</id>
</attributes>
</entity>
</entity-mappings>
This is the entity code:
public class HabitatSpeciesLink implements Serializable
{
private static final long serialVersionUID = -7079021236893433038L;
private Long habitatId;
private Long speciesId;
public static class HabitatSpeciesLinkId implements Serializable
{
//private static final long serialVersionUID = 6224703642788723112L;
private Long habitatId;
private Long speciesId;
public Long getHabitatId()
{
return this.habitatId;
}
public void setHabitatId(Long newHabitatId)
{
this.habitatId = newHabitatId;
}
public Long getSpeciesId()
{
return this.speciesId;
}
public void setSpeciesId(Long newSpeciesId)
{
this.speciesId = newSpeciesId;
}
public boolean equals(Object other)
{
if (other == this)
return true;
if (!(other instanceof HabitatSpeciesLinkId))
return false;
HabitatSpeciesLinkId mi = (HabitatSpeciesLinkId) other;
return (habitatId == mi.habitatId || (habitatId != null && habitatId
.equals(mi.habitatId)))
&& (speciesId == mi.speciesId || (speciesId != null && speciesId
.equals(mi.speciesId)));
}
public int hashCode()
{
return ((habitatId == null) ? 0
: habitatId.hashCode()) ^ ((speciesId == null) ? 0
: speciesId.hashCode());
}
public String toString()
{
return "habitatId[" + habitatId + "],speciesId[" + speciesId + "]";
}
}
public Long getHabitatId()
{
return this.habitatId;
}
public void setHabitatId(Long newHabitatId)
{
this.habitatId = newHabitatId;
}
public Long getSpeciesId()
{
return this.speciesId;
}
public void setSpeciesId(Long newSpeciesId)
{
this.speciesId = newSpeciesId;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((this.getHabitatId() == null) ? 0
: this.getHabitatId().hashCode());
result = prime * result + ((this.getSpeciesId() == null) ? 0
: this.getSpeciesId().hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof HabitatSpeciesLink))
return false;
final HabitatSpeciesLink other = (HabitatSpeciesLink) obj;
if (this.getHabitatId() == null)
{
if (other.getHabitatId() != null)
return false;
}
else if (!this.getHabitatId().equals(other.getHabitatId()))
return false;
if (this.getSpeciesId() == null)
{
if (other.getSpeciesId() != null)
return false;
}
else if (!this.getSpeciesId().equals(other.getSpeciesId()))
return false;
return true;
}
}
This is the test code:
EntityManager entityManager = entityManagerFactory.createEntityManager();
HabitatSpeciesLink.HabitatSpeciesLinkId id = new HabitatSpeciesLink.HabitatSpeciesLinkId();
id.setHabitatId(new Long(123));
id.setSpeciesId(new Long(234));
HabitatSpeciesLink entity = entityManager.find(HabitatSpeciesLink.class, id);
Assert.assertNotNull("should have entity with composite key", entity);
Here's the stacktrace:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [org.permacode.HabitatSpeciesLink#component[habitatId,speciesId]{habitatId=123, speciesId=234}]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:195)
at org.permacode.BugCompositeKeyTest.testCompositeKey(BugCompositeKeyTest.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [org.permacode.HabitatSpeciesLink#component[habitatId,speciesId]{habitatId=123, speciesId=234}]
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:1865)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2992)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:175)
... 23 more
Caused by: java.sql.SQLException: Column 'HABITATSPE0_.HABITATID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'HABITATSPE0_.HABITATID' is not a column in the target table.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1851)
... 35 more
Caused by: ERROR 42X04: Column 'HABITATSPE0_.HABITATID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'HABITATSPE0_.HABITATID' is not a column in the target table.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ColumnReference.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumn.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumnList.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 48 more
I'm using Derby, Hypersonic, H2 or postgresql. It seems to be database-independent.
This is the generated SQL:
select habitatspe0_.habitatId as habitatId0_0_, habitatspe0_.speciesId as speciesId0_0_ from DEV.HABITAT_SPECIES_LINK habitatspe0_ where habitatspe0_.habitatId=? and habitatspe0_.speciesId=?
--
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
[Hibernate-JIRA] Created: (ANN-685) Hibernate does not honor @Column(name=...) annotation with IdClass
by Steve Devore (JIRA)
Hibernate does not honor @Column(name=...) annotation with IdClass
------------------------------------------------------------------
Key: ANN-685
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-685
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.2.1
Environment: Hibernate 3.2.1, JBoss 4.0.4
Reporter: Steve Devore
When an Entity uses an IdClass, any query will fail fails because it is using the name of the attribute instead of the one indicated by the @Column annotation. It fails because it is looking for the annotations of the IdClass instead of the main class.
Please see the following example:
The IdClass is defined as follows:
public class DomainAdminId implements Serializable {
private String domainName;
private String adminUser;
public DomainAdminId() {
}
public DomainAdminId(String domainName, String adminUser) {
this.domainName = domainName;
this.adminUser = adminUser;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
public boolean equals(Object o) {
return ((o instanceof DomainAdminId) &&
domainName.equals(((DomainAdminId)o).getDomainName()) &&
adminUser.equals(((DomainAdminId)o).getAdminUser()));
}
public int hashCode() {
return (domainName+adminUser).hashCode();
}
}
And the following Entity using that idClass:
@Entity
@Table(name="domainadmin")
@IdClass(DomainAdminId.class)
@NamedQueries( {
@NamedQuery(name = "DomainAdmin.test", query = "SELECT d FROM DomainAdmin d")
)
public class DomainAdmin implements Serializable {
@Id
@Column(name="domain_name")
private String domainName;
@Id
@Column(name="adminuser")
private String adminUser;
public DomainAdmin() {
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getAdminUser() {
return adminUser;
}
public void setAdminUser(String adminUser) {
this.adminUser = adminUser;
}
}
When executing the DomainAdmin.test Named Query I got this error:
could not execute query [select domainadmi0_.adminUser as adminUser1_, domainadmi0_.domainName as domainName1_ from domainadmin domainadmi0_]
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'domainadmi0_.domainName' in 'field list'
In effect, as indicated in the source, the column name is "domain_name" and not "domainName".
The same apply for the other column: adminUser (that should instead be "adminuser"),
Workaround:
If the @Column annotation is put on the IdClass it will work sucessfully. However, this should not be necessary.
--
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
[Hibernate-JIRA] Created: (HHH-3590) Having @version in Parent causes wrong HQL update when updating subclass in Joined Subclass Inheritance Strategy.
by Rachit (JIRA)
Having @version in Parent causes wrong HQL update when updating subclass in Joined Subclass Inheritance Strategy.
-----------------------------------------------------------------------------------------------------------------
Key: HHH-3590
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3590
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.1
Environment: Java 1.5 , Oracle 10g , Hibernate 3.3.1.GA
Reporter: Rachit
Priority: Blocker
A very simple joined subclass strategy implemented.
2 classes: Employee(parent/superclass) and Person( child/subclass)
Employee has @Version defined on column ROW_VERSION and Person extends Employee using Joined Inheritance Strategy. Person has PERSON_ID as PK and Employee has EMPLOYEE_ID as PK. I also have @PrimaryKeyJoinColumn(name = "PERSON_ID", referencedColumnName = "EMPLOYEE_ID") for obvious reason.
Now if I update any attribute in Child class i.e Person.setVIPFlag("Y") , hibernate fires an update query on Parent entity with wrong column name in hql. In this case the query would be "update EMPLOYEE set ROW_VERSION=? where PERSON_ID=? and ROW_VERSION=?". This query fails as EMPLOYEE does not have PERSON_ID.
The moment I remove @Version annotation from Parent(Employee) class, there is no update ( as expected ) and hence no error, but this is not an acceptable solution.
Thanking in anticipation.
--
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