[Hibernate-JIRA] Created: (HHH-5792) Unable to JOIN embedded objects in Criteria API
by scLee (JIRA)
Unable to JOIN embedded objects in Criteria API
-----------------------------------------------
Key: HHH-5792
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5792
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager, query-criteria
Affects Versions: 3.6.0
Reporter: scLee
Priority: Blocker
Attachments: Client.java, CriteriaApiTest.java, Name.java
Exception is thrown when trying to JOIN embedded attribute in Criteria API. E.g. having the following entity:
{quote}
@Entity
public class Client implements Serializable {
@Id
public int id;
@Embedded
public Name name;
}
@Embeddable
public class Name implements Serializable {
@Column
public String firstName;
@Column
public String lastName;
}
{quote}
The following code
{quote}
CriteriaQuery< Client > cq = cb.createQuery( Client.class );
Root< Client > root = cq.from( Client.class );
cq.where( cb.equal( root.*join*( "name" ).get( "firstName" ), "foo" ) );
{quote}
throws this exception:
{quote}
java.lang.ClassCastException: org.hibernate.ejb.metamodel.SingularAttributeImpl cannot be cast to javax.persistence.metamodel.ManagedType
at org.hibernate.ejb.criteria.path.AbstractFromImpl.locateManagedType(AbstractFromImpl.java:151)
at org.hibernate.ejb.criteria.path.AbstractFromImpl.locateAttributeInternal(AbstractFromImpl.java:145)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.locateAttribute(AbstractPathImpl.java:216)
at org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:449)
at org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:433)
at foo.CriteriaApiTest.embeddableInPath(CriteriaApiTest.java:45)
{quote}
--
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
11 years, 10 months
[Hibernate-JIRA] Created: (HHH-2796) Generated version are incremented by Hibernate
by Heba Tawfik (JIRA)
Generated version are incremented by Hibernate
----------------------------------------------
Key: HHH-2796
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2796
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Environment: 3.2.1, Oracle 10g
Reporter: Heba Tawfik
Creating a new entity which it's version is set to generated="always" & saving it, then in the same session adding an object to any of its on-to-many relationships is throwing a StaleObjectStateException.
To regenerate the problem, consider the following code
1- departement.hbm.xml :
----------------------------------------
<hibernate-mapping package="com.myproject.domain">
<class name="Departement" table="Departement">
<id name="id">
<column name="dept_id" />
</id>
<version column="version" generated="always" name="version" type="integer" unsaved-value="null" />
<property name="name" column="name" />
<bag name="employees" inverse="true" cascade="all" lazy="true">
<key column="dept_id"></key>
<one-to-many class="Employee" />
</bag>
</class>
</hibernate-mapping>
2- employee.hbm.xml :
--------------------------------------
<hibernate-mapping package="com.myproject.domain">
<class name="Employee" table="Employee">
<id name="id">
<column name="employee_id" />
</id>
<property name="firstName" column="first_name" />
<property name="lastName" column="last_name" />
<property name="age" column="age" />
<property name="salary" column="salary" />
<many-to-one cascade="none"
class="com.myproject.domain.Departement"
column="dept_id" embed-xml="true" insert="false"
name="department" not-null="false"
unique="false" update="false" not-found="ignore">
</many-to-one>
</class>
</hibernate-mapping>
3- Departement.Java
---------------------------
package com.myproject.domain;
import java.util.ArrayList;
import java.util.List;
public class Departement extends BaseDepartement{
int id;
String name;
List employees;
Integer version;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public List getEmployees() {
return employees;
}
public void setEmployees(List employees) {
this.employees = employees;
}
public void addToEmployeeList(Employee emp)
{
if(employees==null)
{
setEmployees(new ArrayList());
}
employees.add(emp);
}
}
4- Employee.Java :
---------------------------
package com.myproject.domain;
public class Employee {
int id;
String firstName;
String lastName;
int age;
int salary;
BaseDepartement department;
public BaseDepartement getDepartment() {
return department;
}
public void setDepartment(BaseDepartement department) {
this.department = department;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
4- Code To Test :
------------------------
public static void main(String args[]) throws Exception
{
SessionFactory factory = new Configuration().configure("com/myproject/config/hibernate.cfg.xml").buildSessionFactory();
Session session = factory.openSession();
Transaction transaction = session.beginTransaction();
Departement aDept =new Departement();
aDept.setId(10);
aDept.setName("Test");
session.save(aDept);
transaction.commit();
transaction = session.beginTransaction();
Employee emp=new Employee();
emp.setId(10);
emp.setFirstName("test");
emp.setLastName("test");
emp.setSalary(10);
emp.setAge(10);
emp.setDepartment(aDept);
aDept.addToEmployeeList(emp);
session.saveOrUpdate(aDept);
transaction.commit();
session.close();
}
On the database, the default value for version cloumn is set to "1" and a trigger is defined as follow on the Departement table:
create or replace
TRIGGER TRIGGER1
BEFORE UPDATE ON DEPARTEMENT
FOR EACH ROW
BEGIN
:new.version:= :old.version + 1;
END;
Upon executing the above code, the following is the hibernate logging :
automatically flushing session
/* insert com.eds.myproject.domain.Departement
*/ insert
into
Departement
(name, dept_id)
values
(?, ?)
binding 'Test' to parameter: 1
binding '10' to parameter: 2
/* get generated state com.eds.myproject.domain.Departement */ select
departemen_.version as version1_
from
Departement departemen_
where
departemen_.dept_id=?
binding '10' to parameter: 1
returning '1' as column: version1_
before transaction completion
after transaction completion
automatically flushing session
/* get current state com.eds.myproject.domain.Employee */ select
employee_.employee_id,
employee_.first_name as first2_0_,
employee_.last_name as last3_0_,
employee_.age as age0_,
employee_.salary as salary0_
from
Employee employee_
where
employee_.employee_id=?
binding '10' to parameter: 1
/* insert com.eds.myproject.domain.Employee
*/ insert
into
Employee
(first_name, last_name, age, salary, employee_id)
values
(?, ?, ?, ?, ?)
binding 'test' to parameter: 1
binding 'test' to parameter: 2
binding '10' to parameter: 3
binding '10' to parameter: 4
binding '10' to parameter: 5
/* update
com.eds.myproject.domain.Departement */ update
Departement
set
name=?
where
dept_id=?
and version=?
binding 'Test' to parameter: 1
binding '10' to parameter: 2
binding '2' to parameter: 3
Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.eds.myproject.domain.Departement#10]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.eds.myproject.test.Test.main(Test.java:43)
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.eds.myproject.domain.Departement#10]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.eds.myproject.test.Test.main(Test.java:43)
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (HSEARCH-726) Facetted search on embedded collections takes only first element from collection
by Elmer van Chastelet (JIRA)
Facetted search on embedded collections takes only first element from collection
--------------------------------------------------------------------------------
Key: HSEARCH-726
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-726
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.4.0.CR2, 3.4.0.CR1, 3.4.0.Beta1, 3.4.0.Alpha1
Environment: Any valid config I suppose, tested using Hibernate Core 3.6.3 + Search 3.4.0.CR2, mysql and in Hibernate Search test environment
Reporter: Elmer van Chastelet
Attachments: EmbeddedCollectionsFacetsTest.zip
>From [Hibernate Search Forum: Bug or not? Faceted search + embedded fields (*tomany)|https://forum.hibernate.org/viewtopic.php?f=9&t=1010472&start=0].
Faceted search won't work correctly when used on collections. For the cause I quote Hardy Ferentschik : ??The current faceting implementation utilizes the Lucene FieldCache which has a limitation that each document must have a single value for the specified field.??
I can think of many use cases in which faceted search on collections is really needed, some examples:
Facetting on authors when searching for publications
Facetting on ingredients when searching for recipes
Facetting on actors when searching for movies
...
Attached is a hibernate search test case. It fails on retrieving the right amount of matched authors.
Currently I don't have the needed insight to suggest an improvement on current implementation to make it compatible with collections. Hopefully it can be achieved with small changes. Good luck :)
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (HHH-2776) Restrictons.in(..) generates invalid SQL if list of values is empty
by Adrian Smith (JIRA)
Restrictons.in(..) generates invalid SQL if list of values is empty
-------------------------------------------------------------------
Key: HHH-2776
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2776
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.2
Environment: Hibernate 3.2.2.ga, MySQL 4.1.18, Windows XP
Reporter: Adrian Smith
I have classes called A and B. There is a 1:n relationship from A to B.
Class B has the following in its mapping file:
<many-to-one name="a" class="A" column="fk_a_id" not-null="true" />
If I write the following code:
List<B> foo() {
List<A> aList = ....
Session session = ....
Criteria query = session.createCriteria(B.class);
query.add(Restrictions.in("a", aList));
return query.list();
}
Then all works fine and the results I want are returned. However, if aList is empty (i.e. aList.size()==0) then the query.list function generates and executes invalid SQL for MySQL.
java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1"
I imagine that it is generating SQL like IN () which isn't valid.
I realize it's a bit ridiculous to want to find the rows where a field is IN the empty list. Nothing will ever be returned. However, in my opinion it should still be allowed, and return no rows, just as saying "WHERE 1=2" is allowed, just doesn't return any rows.
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (HCANN-17) SecondaryTable JoinColumn cannot reference a non primary key
by Krashan Brahmanjara (JIRA)
SecondaryTable JoinColumn cannot reference a non primary key
------------------------------------------------------------
Key: HCANN-17
URL: http://opensource.atlassian.com/projects/hibernate/browse/HCANN-17
Project: Hibernate Commons Annotations
Issue Type: Bug
Affects Versions: 3.1.0.GA
Environment: Hibernate libraries added to jboss-6.0.0.20100216-M2(3.5) and jboss-5.1.0.GA(3.3.1) used with postgresql-8.3.7-1 database and jdbc driver postgresql-8.3-603.jdbc4.jar
Reporter: Krashan Brahmanjara
Hibertate annotations reject correct annotations with an error
Full exception
org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:243)
at org.hibernate.cfg.annotations.EntityBinder.bindJoinToPersistentClass(EntityBinder.java:520)
at org.hibernate.cfg.annotations.EntityBinder.createPrimaryColumnsToSecondaryTable(EntityBinder.java:510)
at org.hibernate.cfg.annotations.EntityBinder.finalSecondaryTableBinding(EntityBinder.java:441)
at org.hibernate.cfg.SecondaryTableSecondPass.doSecondPass(SecondaryTableSecondPass.java:25)
Example
Three entity, two connected to main 'dokument' by their id columns
@Entity
@Table(name = "dokument")
@SecondaryTables(value = {
@SecondaryTable(name = "dokument_status", pkJoinColumns = @PrimaryKeyJoinColumn(name = "id_status", referencedColumnName = "id_status")),
@SecondaryTable(name = "typ_dok", pkJoinColumns = @PrimaryKeyJoinColumn(name = "id_type", referencedColumnName = "id_type")) })
public class PosrDokument implements Serializable {
@Id
@Column(name="id_dokumentu", unique=true, nullable=false)
private int id_dokumentu;
@Column(name = "status", table = "dokument_status", nullable = false, insertable = false, updatable = false)
private String status;
@Column(name = "name", table = "typ_dok", nullable = false, insertable = false, updatable = false)
private String name;
(...)
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (HHH-2831) Native SQL queries with addJoin or <return-join/> return object arrays instead of single Entities
by Jeremy Grodberg (JIRA)
Native SQL queries with addJoin or <return-join/> return object arrays instead of single Entities
-------------------------------------------------------------------------------------------------
Key: HHH-2831
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2831
Project: Hibernate3
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.5, 3.2.4
Environment: Hibernate 3.2.4.ga and 3.2.5.ga with hsqldb on Win XP
Reporter: Jeremy Grodberg
Attachments: NativeSQLQueriesTest.patch
Although the documentation is not crystal clear, I read it to say that using addJoin should eagerly fetch an associated object but should NOT return it as a separate value. In section 16.1.3. "Handling associations and collections" of the online documentation it says: "It is possible to eagerly join in the Dog to avoid the possible extra roundtrip for initializing the proxy. This is done via the addJoin() method, which allows you to join in an association or collection." This comes BEFORE the section on returning multiple entities, so I say the documentation at least implies it will only return a single entity at the top level. Also, if the intention is to return multiple entities, addEntity() works fine for that, so what then would be the difference of addJoin()? If I'm wrong about what addJoin() should do, please clarify that in the documentation and also clarify how, if it is possible, one could eagerly fetch the association without changing the return type of the quer
y.
I have reproduced this problem in the Hibernate JUnit tests in 3.2.4.ga and 3.2.5.ga, specifically NativeSQLQueriesTest.testSQLQueryInterface().
I'm attaching a patch to the Hibernate junit test org.hibernate.test.sql.hand.query.NativeSQLQueriesTest.java released in 3.2.5.ga that adds a test to ensure that a query with addJoin only returns a (list of) entities, not a list of Object arrays containing entities. Currently, the assertion fails because instead of returning a list of Organizations we get a list of Object[3] = { Organization, Employment, Person }, which is exactly what we get when the addJoin()s are replaced with appropriate addEntity() calls.
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (BVAL-198) Simplify creation of ConstraintViolationExceptions
by Gunnar Morling (JIRA)
Simplify creation of ConstraintViolationExceptions
--------------------------------------------------
Key: BVAL-198
URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-198
Project: Bean Validation
Issue Type: Improvement
Components: spec-general
Affects Versions: 1.1
Reporter: Gunnar Morling
javax.validation.ConstraintViolationException wraps a set of constraint violations, currently in the following form:
Set<ConstraintViolation<?>> constraintViolations
As the exception's constructors have a parameter of the same type, instantiating it is not as easy as expected:
Validator validator = ...;
DomainObject domainObject = new DomainObject();
Set<ConstraintViolation<DomainObject>> constraintViolations = validator.validate(domainObject);
//compiler error: ("The constructor ConstraintViolationException(Set<ConstraintViolation<DomainObject>>) is undefined")
throw new ConstraintViolationException(constraintViolations);
//this works
throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(constraintViolations));
This problem can be solved by changing the collection type to
Set<? extends ConstraintViolation<?>>
The exception then would read as follows:
public class ConstraintViolationException extends ValidationException {
private final Set<? extends ConstraintViolation<?>> constraintViolations;
public ConstraintViolationException(String message, Set<? extends ConstraintViolation<?>> constraintViolations) {
super( message );
this.constraintViolations = constraintViolations;
}
public ConstraintViolationException(Set<? extends ConstraintViolation<?>> constraintViolations) {
super();
this.constraintViolations = constraintViolations;
}
public Set<ConstraintViolation<?>> getConstraintViolations() {
return new HashSet<ConstraintViolation<?>>(constraintViolations);
}
}
This makes the exception easier to use for producers, while maintaining simplicity for clients (since getConstraintViolations() still returns a Set<ConstraintViolation<?>>, clients don't have to do deal with the bound wildcard expression).
--
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
11 years, 11 months
[Hibernate-JIRA] Created: (HHH-6127) Wrong save or read unicode value on @Lob String field in PostgreSQL 8.4
by Mihail Slobodyanuk (JIRA)
Wrong save or read unicode value on @Lob String field in PostgreSQL 8.4
-----------------------------------------------------------------------
Key: HHH-6127
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6127
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.3
Environment: PostgreSQL 8.4.5 on Ubuntu 32, Hibernate 3.6.0 - 3.6.3, jdbc driver: postgresql-8.3-603.jdbc3
Reporter: Mihail Slobodyanuk
Priority: Critical
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/test</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
@Entity
public class ReportTemplate{
@Id
@GeneratedValue
private Integer id;
@Lob
private String body;
...
}
At save (or at read) operation with 'body' field value is broken. In DB stored Blob's OID.
The next code throw AssertionError:
String str="Русский текст";//Unicode string
rt = new ReportTemplate();
rt.setBody(str);
Serializable id = hsm.getSession().save(rt);
hsm.commit();
hsm.getSession().clear();
rt = (ReportTemplate) hsm.getSession().get(ReportTemplate.class, id);
assert str.equals(rt.getBody());
--
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
11 years, 11 months