[Hibernate-JIRA] Commented: (HHH-1088) IdentifierProjection does not work with composite keys
by Michael Grünewald (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088?page=c... ]
Michael Grünewald commented on HHH-1088:
----------------------------------------
Sorry, had overlooked, that this solution was already suggested in the bug report.
> IdentifierProjection does not work with composite keys
> ------------------------------------------------------
>
> Key: HHH-1088
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1 rc2
> Reporter: Max Muermann
> Attachments: CompositeIdProjection.java, CriteriaLoader.java
>
>
> When working with Criteria queries, the IdentifierProjection breaks if the entity has a composite key.
> In IdentifierProjection.java:
> public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
> throws HibernateException {
> StringBuffer buf = new StringBuffer();
> String[] cols = criteriaQuery.getIdentifierColumns(criteria);
> for ( int i=0; i<cols.length; i++ ) {
> buf.append( cols[i] )
> .append(" as y")
> .append(position + i)
> .append('_');
> }
> return buf.toString();
> }
> This method does not add commas as separators between the column names. Easily fixed by adding
> if (i<col.length-1)
> buf.append(",");
> as the last statement inside the loop.
> However, this leads to another problem:
> the type returned by IdentifierProjection.geType is the (single) type of the composite id component. The query will however return the property values of the id component without a mapping step.
--
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, 11 months
[Hibernate-JIRA] Commented: (HHH-1088) IdentifierProjection does not work with composite keys
by Michael Grünewald (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088?page=c... ]
Michael Grünewald commented on HHH-1088:
----------------------------------------
Hi, I have the same problem.
Hibernate just creates wrong SQl like this:
"select this_.comment as y0_this_.name as y1_this_.type as y2_this_.year as y3_ from CountryModel this_"
It recognizes that their is an compund key but don't use the right syntax.
Cause:
"select this_.comment as y0_, this_.name as y1_, this_.type as y2_, this_.year as y3_ from CountryModel this_"
would be correct, just a separating comma and space are missing if more than one identifier is used.
According to the source code from IdentifierProjection:
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
throws HibernateException {
StringBuffer buf = new StringBuffer();
String[] cols = criteriaQuery.getIdentifierColumns(criteria);
for ( int i=0; i<cols.length; i++ ) {
buf.append( cols[i] )
.append(" as y")
.append(position + i)
.append('_');
}
return buf.toString();
adding a simple if -statement should fix it :
public String toSqlString(final Criteria criteria, final int position, CriteriaQuery criteriaQuery)
throws HibernateException {
final StringBuffer buf = new StringBuffer();
final String[] cols = criteriaQuery.getIdentifierColumns(criteria);
for (int i = 0, n = cols.length; i < n; i++) {
buf.append(cols[i]).append(" as y").append(position + i).append('_');
if (i < n - 1) {
buf.append(", ");
}
}
return buf.toString();
}
}
IMHO projections to compound keys makes sense, to avoid manual SQL-Queries especially with eager realations, if you need all key attributes to provide a dialog which the user can choose from.
So if someone can please change the code.
Thanks a lot.
Greetings Michael
> IdentifierProjection does not work with composite keys
> ------------------------------------------------------
>
> Key: HHH-1088
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1088
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1 rc2
> Reporter: Max Muermann
> Attachments: CompositeIdProjection.java, CriteriaLoader.java
>
>
> When working with Criteria queries, the IdentifierProjection breaks if the entity has a composite key.
> In IdentifierProjection.java:
> public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
> throws HibernateException {
> StringBuffer buf = new StringBuffer();
> String[] cols = criteriaQuery.getIdentifierColumns(criteria);
> for ( int i=0; i<cols.length; i++ ) {
> buf.append( cols[i] )
> .append(" as y")
> .append(position + i)
> .append('_');
> }
> return buf.toString();
> }
> This method does not add commas as separators between the column names. Easily fixed by adding
> if (i<col.length-1)
> buf.append(",");
> as the last statement inside the loop.
> However, this leads to another problem:
> the type returned by IdentifierProjection.geType is the (single) type of the composite id component. The query will however return the property values of the id component without a mapping step.
--
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, 11 months
[Hibernate-JIRA] Created: (HHH-3890) Criteria and Query "Interceptor"
by Eric Martineau (JIRA)
Criteria and Query "Interceptor"
--------------------------------
Key: HHH-3890
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3890
Project: Hibernate Core
Issue Type: Improvement
Components: core, query-criteria, query-hql
Reporter: Eric Martineau
It would incredibly useful to be able to intercept every Criteria and Query instance created by a Session. It would allow you to enforce a filter that you wanted to be run on EVERY query to the database.
For example, if you each record in your system had a tenantId and you want to globally restrict queries to only include records for the current tenant:
public class TenantCriteriaInterceptor implements CriteriaInterceptor {
public void intercept(Criteria criteria) {
criteria.add(Expression.eq("tenantId", CurrentTenant.get()));
}
}
This type of functionality would be pretty easy to implement as an add-on to hibernate IF it were possible to extend SessionFactoryImpl. I attempted to implement by using wrap/delegate, but I ran into a bunch of problems with Spring not being able to locate the Session bound to the current thread (sometimes it would try to locate the current session using the wrapped SessionFactoryImpl, sometimes it would use the wrapper).
I have this working perfectly by using a custom hibernate (3.3.1) where SessionFactoryImpl is NOT marked final. I've exhausted all other avenues without any luck - any help would be appreciated.
--
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, 11 months
[Hibernate-JIRA] Created: (HHH-3879) Envers documentation: configuration of event listeners is incomplete for JPA: @PostPersist, @PostUpdate @PostRemove no longer work
by Erik-Berndt Scheper (JIRA)
Envers documentation: configuration of event listeners is incomplete for JPA: @PostPersist, @PostUpdate @PostRemove no longer work
-----------------------------------------------------------------------------------------------------------------------------------
Key: HHH-3879
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3879
Project: Hibernate Core
Issue Type: Task
Components: envers
Affects Versions: 3.3.x, 3.5
Reporter: Erik-Berndt Scheper
The Envers documentation proscribes the following configuration for JPA:
<property name="hibernate.ejb.event.post-insert"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
value="org.hibernate.envers.event.AuditEventListener" />
However, this conflicts with chapter 2.3 Event listeners in the Hibernate Entitymanager configuration, which states:
<quote form entitymanager documentation>
Hibernate Entity Manager needs to enhance Hibernate core to implements all the EJB3 semantics. It does that through the event listener system of Hibernate. Be careful when you use the event system yourself, you might override some of the EJB3 semantics. A safe way is to add your event listeners to the list given below.
<table skipped>
Note that the JACC*EventListeners are removed if the security is not enabled.
</quote form entitymanager documentation>
I have found that this is correct: when I use the proscribed configuration the following JPA annotations no longer work: @PostPersist, @PostUpdate @PostRemove
To fix this, I have changed the configuration to:
<property name="hibernate.ejb.event.post-insert"
value="org.hibernate.ejb.event.EJB3PostInsertEventListener, org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
value="org.hibernate.ejb.event.EJB3PostUpdateEventListener, org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
value="org.hibernate.ejb.event.EJB3PostDeleteEventListener, org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-update"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-remove"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-collection-recreate"
value="org.hibernate.envers.event.AuditEventListener" />
Please update the envers documentation accordingly.
--
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, 11 months
[Hibernate-JIRA] Created: (HHH-3888) Envers schema generation (ant) ignoring columnDefinition ( atribute of @Column, JPA )
by Euclides Melo (JIRA)
Envers schema generation (ant) ignoring columnDefinition ( atribute of @Column, JPA )
-------------------------------------------------------------------------------------
Key: HHH-3888
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3888
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.3.1
Environment: Ubuntu 32bit 8.10, sun jdk 1.6.12, Envers 1.2.0GA, JPA 1.0, Hibernate 3.3.1GA, Annotations and EntityManager 3.4.0GA
Reporter: Euclides Melo
I am using the org.hibernate.tool.ant.EnversHibernateToolTask with jpaconfiguration .
It is working fine, except with this case: I have a class with this attribute:
Code:
@Column(columnDefinition="text", nullable=true)
private String foo;
The generated tables are the following:
Code:
create table Bar ( foo text null, other fields... //CORRECT
create table Bar_AUD ( foo varchar(255) null, other fields... //BUG! should be text, not the default varchar(255)
Note the AUD table, it is ignoring the columnDefinition .
I am using Envers 1.2.0 GA.
This is a similar problem found on
https://jira.jboss.org/jira/browse/ENVERS-70
--
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, 11 months