[Hibernate-JIRA] Created: (HHH-5998) Illegal parenthesis in generated Oracle SQL SELECT clause (when using subselect)
by Thomas Zangerl (JIRA)
Illegal parenthesis in generated Oracle SQL SELECT clause (when using subselect)
--------------------------------------------------------------------------------
Key: HHH-5998
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5998
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.6.0
Environment: Hibernate 3.6.0.Final (shipped as part of JBoss runtime environment 6), Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit
Reporter: Thomas Zangerl
Hi,
when using an HQL subselect with EXISTS where the selected object in the subselect is an entity with a composite primary key (mapping a join-table), Hibernate adds parenthesis to the query-list with the selected columns. Oracle does not accept SELECT statements with parenthesis around the query-list and fails.
Consider the following entities (non-relevant members omitted):
{code:java}
@Entity
@Table(name = "DEMANDE_MODULES")
public class ModulesRequest implements Serializable {
/**
* generated serialVersionUID
*/
private static final long serialVersionUID = -9083049226182530936L;
private Long id;
@Id
@Column(name = "DMD_ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="demandeSeq")
@SequenceGenerator(name="demandeSeq", sequenceName="S_EVA_DMD_ID", allocationSize = 1)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
{code}
{code:java}
@Entity
@Table(name = "EVALUATION")
public class Evaluation implements Serializable {
/**
* generated serialVersionUID
*/
private static final long serialVersionUID = -7258988774554733242L;
private Long id;
@Id
@Column(name = "EVA_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="evaluationSeq")
@SequenceGenerator(name="evaluationSeq", sequenceName="S_EVA_ID", allocationSize = 1)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
{code}
{code:java}
@Entity
@Table(name = "DEMANDE_EVALUATION")
@AssociationOverrides({
@AssociationOverride(name = "pk.request", joinColumns=@JoinColumn(name = "DMD_ID")),
@AssociationOverride(name = "pk.evaluation", joinColumns=@JoinColumn(name = "EVA_ID"))
})
public class EvaluationRequest implements Serializable {
/**
* generated serialVersionUID
*/
private static final long serialVersionUID = -7511793462359852575L;
private EvaluationRequestId pk;
public EvaluationRequest() {
this.pk = new EvaluationRequestId();
}
@EmbeddedId
public EvaluationRequestId getPk() {
return pk;
}
public void setPk(EvaluationRequestId pk) {
this.pk = pk;
}
}
{code}
{code:java}
@Embeddable
public class EvaluationRequestId implements Serializable {
/**
* generated serialVersionUID
*/
private static final long serialVersionUID = -2708732283791960577L;
private ModulesRequest request;
private Evaluation evaluation;
public void setRequest(ModulesRequest request) {
this.request = request;
}
@ManyToOne
@ForeignKey(name="FK_DMD_EVA_DMD_EVALUATIONS")
public ModulesRequest getRequest() {
return request;
}
public void setEvaluation(Evaluation evaluation) {
this.evaluation = evaluation;
}
@ManyToOne
@ForeignKey(name="FK_DMD_EVA_EVALUATION")
public Evaluation getEvaluation() {
return evaluation;
}
}
{code}
EvaluationRequest is a join table between Evaluation and ModulesRequest, hence the primary key is the composite of the primary keys of Evaluation and ModulesRequest.
If I now execute the following EJB-QL query
{code:java}
String testQuery = "SELECT request " +
"FROM ModulesRequest request " +
"WHERE EXISTS (" +
" SELECT evRequest " +
" FROM request.evaluationRequests evRequest) ";
Query testq = em.createQuery(testQuery);
testq.getResultList();
{code}
Hibernate generates the following SQL command from the above EJB-QL:
{code:sql}
select
modulesreq0_.DMD_ID as DMD1_145_,
modulesreq0_.COMMENTAIRE as COMMENTA2_145_,
modulesreq0_.SFP_ID as SFP3_145_,
modulesreq0_.SEM_ID as SEM4_145_
from
DEMANDE_MODULES modulesreq0_
where
exists (
select
(evaluation1_.EVA_ID,
evaluation1_.DMD_ID)
from
DEMANDE_EVALUATION evaluation1_
where
modulesreq0_.DMD_ID=evaluation1_.DMD_ID
)
{code}
This SQL fails in the second SELECT because Oracle does not accept parantheses in a select statement:
{code}
14:42:41,706 ERROR [org.hibernate.util.JDBCExceptionReporter] ORA-00907: missing right parenthesis
{code}
The parantheses do not get included if the EJBQL selects directly on EvalauationRequest (and not as a part of a subselect in EXISTS).
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (HHH-3843) @Audited and @ManyToMany relation problem - after modyfing an Entity: org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session ...
by Michał Maryniak (JIRA)
@Audited and @ManyToMany relation problem - after modyfing an Entity: org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session ...
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-3843
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3843
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.3.1
Environment: envers.jar 1.2.0, Hibernate 3.3.1, postgresql-8.3, jboss-4.2.3
Reporter: Michał Maryniak
Attachments: enverse.7z
There is a problem with unidirectional @ManyToMany relation.
This case is different than the one with inheritance: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3830.
The example is trival and code is as simple as it can be.
A single Person can have many roles, and one Role can by assigned to many Person entities.
@Entity
@Audited
public class Person implements Serializable {
(...)
@ManyToMany
public List<Role> getRoles() {
return roles;
}
(...)
}
and
@Entity
@Audited
public class Role implements Serializable {
(...)
}
And here comes a use case:
1) I create role 'admin'
2) I create role 'user'
3) I create person 'john' and add him a role 'admin'
4) I edit 'john' and add him second role 'user'
and I got an exception:
org.hibernate.NonUniqueObjectException with message: "a different object with the same identifier value was already associated with the session: [Person_Role_AUD#{roles_id=1, Person_id=5, REV=DefaultRevisionEntity(id = 7, revisionDate = 2009-04-01 10:46:32)}]"
If I add one role and remove the second one, or if I only remove a role - an Exception does not occur.
I attached a zip file with this simple SEAM project generated by seam-gen 2.1.1 GA.
I haven't included jar files, but project requires jar's "generated" with seam-gen (2.1.1) and following jar's have been replaced with new ones:
2008-06-13 13:09 313˙898 dom4j.jar 1.6.1
2009-03-23 13:01 285˙158 envers.jar 1.2.0-hibernate-3.3
2008-08-20 11:27 279˙714 hibernate-annotations.jar 3.4.0.GA
2008-08-20 11:31 66˙993 hibernate-commons-annotations.jar 3.1.0.GA
2008-08-20 12:19 119˙292 hibernate-entitymanager.jar 3.4.0.GA
2008-12-04 14:39 304˙236 hibernate-search.jar 3.1.0.GA
2008-09-10 14:01 62˙574 hibernate-validator.jar 3.1.0.GA
2008-09-10 13:27 2˙766˙130 hibernate.jar from hibernate-distribution-3.3.1.GA-dist
2008-06-13 13:09 13˙236 jta.jar 1.1 (from hibernate-distribution-3.3.1.GA-dist)
2008-12-04 14:41 818˙961 lucene-core.jar 2.4.0 701827 - 2008-10-05 16:44:37
2008-08-19 20:40 17˙384 slf4j-api.jar 1.5.2
If you wish - I can attach a file with my oryginal jar - but it would be a realy big file ;-)
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (HHH-6698) Query Parameters Not Bound Correctly
by Erich Heard (JIRA)
Query Parameters Not Bound Correctly
------------------------------------
Key: HHH-6698
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6698
Project: Hibernate Core
Issue Type: Bug
Components: query-hql, query-sql
Affects Versions: 3.6.0
Environment: Hibernate 3.6.0, Windows, Oracle 10g and MySQL 5.1
Reporter: Erich Heard
When an entity has a compound key made up of, in part, another entity's compound key, it seems that Hibernate does not bind parameters to the correct columns in SQL translated from HQL. It seems that the routine used to build the SQL statement via Antlr can list primary key columns in a different order than the routine that builds parameter values via reflection. Bascially, you end up with a condition like:
PK_COL_1 = ? and
PK_COL_2 = ?
and the bound values are for :pkCol2 and :pkCol1 respectively. Depending on how an HQL query is written, you can actually get the query translator to build a join this way:
TABLE1.PK_COL_1 = TABLE2.PK_COL_2 and
TABLE1.PK_COL_2 = TABLE2.PK_COL_1
Depending on the data type, this can either cause an error or an empty result set. I did a good bit of debugging, but did not find an easy solution that didn't break something else worse. I did find that explicitly setting @JoinColumn.referencedColumnName in the child ID class did force things to work correctly against Oracle but MySQL is syntactically different enough that it does not work there. I will attach an example shortly.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 2 months
[Hibernate-JIRA] Created: (HV-443) Scope of ConstraintDescriptors sometimes wrong in type hierarchies
by Gunnar Morling (JIRA)
Scope of ConstraintDescriptors sometimes wrong in type hierarchies
------------------------------------------------------------------
Key: HV-443
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-443
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.1.0.Final
Reporter: Gunnar Morling
Fix For: 4.2.0.CR1
Using the BV meta data API it is possible to retrieve meta information on the constraints of given Java types. Using the {{ConstraintFinder}} API the scope of the constraints to retrieve meta data for can be restricted.
Due to the caching of meta data in {{BeanMetaDataCache}} it can happen under certain circumstances that constraints are declared in scope {{LOCAL_ELEMENT}}, although it should be {{HIERARCHY}} instead.
The following test demonstrates the bug:
{code:java}
public class CacheTest {
@Test
public void constraintsFromSuperTypeAreInLocalScopeWhenSuperTypeIsLoadedFromCache() {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
// loads BeanMetaData for A and puts it into the BeanMetaDataCache
PropertyDescriptor propertyDescriptorForSuperType = validator
.getConstraintsForClass(A.class).getConstraintsForProperty("foo");
Set<ConstraintDescriptor<?>> constraintDescriptorsFromSuperType = propertyDescriptorForSuperType
.findConstraints().lookingAt(Scope.LOCAL_ELEMENT)
.getConstraintDescriptors();
assertEquals(constraintDescriptorsFromSuperType.size(), 1);
// re-uses BeanMetaData for A from cache, keeps A's constraints in
// LOCAL_ELEMENT scope
PropertyDescriptor propertyDescriptorForSubType = validator
.getConstraintsForClass(B.class).getConstraintsForProperty("foo");
Set<ConstraintDescriptor<?>> constraintDescriptorsFromSubType = propertyDescriptorForSubType
.findConstraints().lookingAt(Scope.LOCAL_ELEMENT)
.getConstraintDescriptors();
// fails
assertEquals(constraintDescriptorsFromSubType.size(), 0, "No descriptor in LOCAL scope expected for B.foo");
}
@Test
public void constraintsFromSuperTypeAreInHierarchyScopeWhenSuperTypeIsNotLoadedFromCache() {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
// loads BeanMetaData for A when traversing B's hierarchy, A's constraints
// are correctly in HIERARCHY scope
PropertyDescriptor propertyDescriptorForSubType = validator
.getConstraintsForClass(B.class).getConstraintsForProperty("foo");
Set<ConstraintDescriptor<?>> constraintDescriptorsFromSubType = propertyDescriptorForSubType
.findConstraints().lookingAt(Scope.LOCAL_ELEMENT)
.getConstraintDescriptors();
assertEquals(constraintDescriptorsFromSubType.size(), 0, "No descriptor in LOCAL scope expected for B.foo");
constraintDescriptorsFromSubType = propertyDescriptorForSubType
.findConstraints().lookingAt(Scope.HIERARCHY)
.getConstraintDescriptors();
assertEquals(constraintDescriptorsFromSubType.size(), 1, "One descriptor in HIERARCHY scope expected for B.foo");
}
public static class A {
@NotNull
public String getFoo() {
return null;
}
}
public static class B extends A {
}
}
{code}
The bug is caused by retrieving the meta data for {{A}} from the cache when building the meta data for its sub-type {{B}} (see {{constraintsFromSuperTypeAreInLocalScopeWhenSuperTypeIsLoadedFromCache}}). In this case the constraint from {{A}} are added to {{B}} but remain in scope {{LOCAL_ELEMENT}}.
The bug does not occur when the meta data for {{A}} is retrieved when traversing the type hierarchy while building up the meta data for {{B}} (see {{constraintsFromSuperTypeAreInHierarchyScopeWhenSuperTypeIsNotLoadedFromCache}}), though I guess the constraints would be wrongly in scope {{HIERARCHY}} if afterwards the descriptors for {{A}} itself would be retrieved.
To fix this bug the constraint scope needs to be re-determined always if the meta data is retrieved from the cache.
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (HV-480) Constraints configured via XML and programmatic API aren't merged
by Gunnar Morling (JIRA)
Constraints configured via XML and programmatic API aren't merged
-----------------------------------------------------------------
Key: HV-480
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-480
Project: Hibernate Validator
Issue Type: Bug
Reporter: Gunnar Morling
Fix For: 4.x
The HV reference guide says
{quote}
[The programmatic] API can be used exclusively or in combination with annotations and xml. If used in combination programmatic constraints are additive to otherwise configured constraints.
{quote}
While that is right for constraints configured via annotations and programmatic API this does currently not work for constraints configured via XML and programmatic API. Currently a type's XML configuration has precedence over its programmatic configuration. The cause is that once the meta data for a type is added to the bean meta data cache in {{ValidatorFactoryImpl#initXmlConfiguration()}} programmatic meta data won't be added or merged in {{initProgrammaticConfiguration()}}.
--
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
13 years, 2 months
[Hibernate-JIRA] Created: (HHH-6188) java.util.UUID cannot be used for Ids
by Thomas Oellrich (JIRA)
java.util.UUID cannot be used for Ids
-------------------------------------
Key: HHH-6188
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6188
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.3
Environment: Hibernate 3.6.3Final, Oracle 9i
Reporter: Thomas Oellrich
Attachments: Foo.java, foo.sql, fullstacktrace.txt
Hibernate successfully maps java.util.UUID to a database field defined as raw(16) in Oracle. However, as soon as I add the @Id annotation from the JPA-API, I get the following error:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -2
at org.hibernate.dialect.TypeNames.get(TypeNames.java:77)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:100)
at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:296)
at org.hibernate.mapping.Column.getSqlType(Column.java:208)
at org.hibernate.mapping.Table.sqlTemporaryTableCreateString(Table.java:371)
at org.hibernate.mapping.PersistentClass.prepareTemporaryTables(PersistentClass.java:774)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:272)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
I'm using org.hibernate.dialect.Oracle9iDialect.
--
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
13 years, 2 months