[Hibernate-JIRA] Created: (HHH-2787) Criteria Aggregate Projections do not JOIN additional tables on which restrictions apply
by Sami Dalouche (JIRA)
Criteria Aggregate Projections do not JOIN additional tables on which restrictions apply
----------------------------------------------------------------------------------------
Key: HHH-2787
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2787
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.5
Environment: PostgreSQL Dialect
Reporter: Sami Dalouche
Priority: Critical
Hi,
When you have a Criteria Object, on which you :
- Add Aggregate Projections such as rowCount()
- createAlias("whatever").add(Restrictions.*..)
It looks like that the "whatever" table is NOT joined, even though it is joined OK when the projections are not there.
So, here is an approximate Unit test that should throw an exception (I couldn't create a complete test case since I couldn't get the unit tests to run on my machine -any link explaining this step somewhere ?):
Criteria c1 = s.createCriteria(Enrolment.class)
.setProjection( Projections.projectionList().add(Projections.rowCount(), "rowCount") );
Criteria studentCriteria = c1.createAlias("student", "st");
studentCriteria.add(Restrictions.eq("name", "whatevername"));
It should complain saying the "st.name" alias does not exist, because the student class has not been joined.
Regards,
Sami Dalouche
--
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
16 years, 1 month
[Hibernate-JIRA] Created: (ANN-730) Still incorrect FK circularity errors
by Lars Heyden (JIRA)
Still incorrect FK circularity errors
-------------------------------------
Key: ANN-730
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-730
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.1.GA
Environment: Hibernate 3.2.6.ga, HEM3.3.2.ga, HAN3.3.1.ga,
JSE 1.6, DB2 8.2
Reporter: Lars Heyden
Attachments: cyclic-test.zip
This bug is related to ANN-694 (and some other issues).
Correctly mapped JoinedSubclasses still get reported to have circularities in their FKs which is not the case.
To reproduce the bug at least four entity classes must be in a joined class hierarchy. As in ANN-694 there is a workaround by renaming the tables to force another processing order.
I've provided a small test case:
It consists of four entities ClassA, ClassB, ClassC and ClassD mapped with InheritanceType.JOINED to the tables "class_a", "class_b", "class_c" and "class_1d". Because ClassD maps to table "class_1d" it gets processed first by the circularity check which raises the error.
--
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
16 years, 1 month
[Hibernate-JIRA] Commented: (HB-92) Retrieving native generated identifiers does not support generic Hibernate types
by Chris Webb (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HB-92?page=com.... ]
Chris Webb commented on HB-92:
------------------------------
Tested against Hibernate Core v3.3.1 GA and original issue still exists. Not sure how to use PostInsertIdentifierGenerator to resolve. The more recent version of org.hibernate.id.IdentifierGeneratorFactory in this release allows for a new solution by modifying the method get(ResultSet rs, Type type) to attempt calling an appropriate constructor on the 'returned class' to create the identifier object as follows:
public static Serializable get(ResultSet rs, Type type) throws SQLException, IdentifierGenerationException {
Class clazz = type.getReturnedClass();
if ( clazz == Long.class ) {
return new Long( rs.getLong( 1 ) );
}
else if ( clazz == Integer.class ) {
return new Integer( rs.getInt( 1 ) );
}
else if ( clazz == Short.class ) {
return new Short( rs.getShort( 1 ) );
}
else if ( clazz == String.class ) {
return rs.getString( 1 );
}
else {
// >>>>>> START NEW LOGIC
// Now check to see if the returned class wraps the returned result
// set field. Assumes the returned class defines an appropriate
// public constructor.
// TODO: Rather then assuming an appropriate constructor and using
// reflection maybe the type should define a method that takes a
// result set and returns the appropriate identifier type.
Object identifierValue = null;
try {
try {
Constructor<Serializable> constructor = clazz.getConstructor(new Class[] { long.class});
identifierValue = new Long(rs.getLong(1));
return constructor.newInstance(new Object[] { identifierValue });
} catch (NoSuchMethodException e) {
try {
Constructor<Serializable> constructor = clazz.getConstructor(new Class[] { int.class});
identifierValue = new Integer(rs.getInt(1));
return constructor.newInstance(new Object[] { identifierValue });
} catch (NoSuchMethodException e1) {
try {
Constructor<Serializable> constructor = clazz.getConstructor(new Class[] { short.class});
identifierValue = new Short(rs.getShort(1));
return constructor.newInstance(new Object[] { identifierValue });
} catch (NoSuchMethodException e2) {
try {
Constructor<Serializable> constructor = clazz.getConstructor(new Class[] { String.class});
identifierValue = rs.getString(1);
return constructor.newInstance(new Object[] { identifierValue });
} catch (NoSuchMethodException e3) {
// Do nothing.
}
}
}
}
} catch (SecurityException e) {
throw new IdentifierGenerationException("Failed to instantiate identifier class '" + clazz + "' with identifier value '" + identifierValue + "'", e);
} catch (IllegalArgumentException e) {
throw new IdentifierGenerationException("Failed to instantiate identifier class '" + clazz + "' with identifier value '" + identifierValue + "'", e);
} catch (InstantiationException e) {
throw new IdentifierGenerationException("Failed to instantiate identifier class '" + clazz + "' with identifier value '" + identifierValue + "'", e);
} catch (IllegalAccessException e) {
throw new IdentifierGenerationException("Failed to instantiate identifier class '" + clazz + "' with identifier value '" + identifierValue + "'", e);
} catch (InvocationTargetException e) {
throw new IdentifierGenerationException("Failed to instantiate identifier class '" + clazz + "' with identifier value '" + identifierValue + "'", e);
}
// <<<<<< END NEW LOGIC
throw new IdentifierGenerationException( "this id generator generates long, integer, short or string or classes that wrap those types" );
}
}
Can this issue be reopend and the above change applied?
> Retrieving native generated identifiers does not support generic Hibernate types
> --------------------------------------------------------------------------------
>
> Key: HB-92
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HB-92
> Project: Hibernate2
> Issue Type: Patch
> Components: core
> Affects Versions: 2.0 final
> Reporter: Chris Webb
> Assignee: Gavin King
> Fix For: 3.0 beta 4
>
> Attachments: patch hb-92.txt
>
>
> At present Hibernate does not support identifier types other than Short, Integer or Long for native generated identifiers. This presents a problem when a user defined type is used to encapsulate an identifier that can support natively generated identifiers. An example is where a identifier type is defined that stores the natively generated value internally as a long, thus is similiar to a Long type but not actually a Long type.
> The solution is to use the actual identifier type to extract the identifer value from the appropriate retrieve identifier SQL result set rather than the method IdentifierGeneratorFactory.get(ResultSet, Class) which in fact has been flagged as inappropriate in the source code documentation.
> A patch has been supplied that does the following:
> 1. Removes the method get(ResultSet, Class) from IdentifierGeneratorFactory.
> 2. Changes SequenceGenerator and AbstractEntityPersister to add an 'id' column alias to the SQL used for retrieving the natively generated identifier.
> 3 Changes SequenceGenerator, EntityPersister and NormalizedEntityPersister to retrieve the identifier value from the SQL result set using the identifer type via the method nullSafeGet(ResultSet rs, String colName, SessionImplementor session, Object owner).
--
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
16 years, 1 month
[Hibernate-JIRA] Created: (ANN-686) SubClass with EmbeddedId or IdClass containing @ManyToOne fail at startup
by Marcos Sousa (JIRA)
SubClass with EmbeddedId or IdClass containing @ManyToOne fail at startup
-------------------------------------------------------------------------
Key: ANN-686
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-686
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.3.1.beta1, 3.3.0.ga
Reporter: Marcos Sousa
Priority: Minor
I subclass Customer that has a EmbeddedId using JOIN inheritance strategy. My embeddable class has @ManyToOne relationship. Look the classes:
Pesson class:
@Entity
@Table(name="person")
public class Person {
@Id
private Integer personId;
private String name;
}
Embeddable class ID.
@Embeddable
public class PersonPk implements Serializable {
@ManyToOne(optional=false,
cascade={CascadeType.PERSIST,
CascadeType.REFRESH,
CascadeType.REMOVE}, fetch=FetchType.EAGER)
@JoinColumn(name="personId")
private Person person;
// ... getters and setters
}
CustomerClass:
@Entity
@Table(name="Customer")
@Inheritance(strategy=InheritanceType.JOINED)
public class Customer {
@Id
private PersonPk pk = new PersonPk();
}
Regional Custumer:
@Entity
@Table(name="AmericanCustomer")
@PrimaryKeyJoinColumn(name="personId")
@IdClass(PessoaPk.class)
public class AmericanCustomer extends Customer {
// some american customer fields..
}
This mapping throw this exception at hibernate startup:
Invocation of init method failed; nested exception is java.util.NoSuchElementException
Caused by:
java.util.NoSuchElementException
at java.util.AbstractList$Itr.next(Unknown Source)
at org.hibernate.util.JoinedIterator.next(JoinedIterator.java:53)
at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumn(Ejb3JoinColumn.java:210)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:463)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:501)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:282)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
--
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
16 years, 1 month