[Hibernate-JIRA] Created: (HHH-5976) ClassCastException when accessing attributes of embedded object through Join structure.
by Jaroslaw Lewandowski (JIRA)
ClassCastException when accessing attributes of embedded object through Join structure.
---------------------------------------------------------------------------------------
Key: HHH-5976
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5976
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.6.0
Reporter: Jaroslaw Lewandowski
Suppose you have class A which has attribute 'a' of type E which is @Embedded type. The following code using criteria API will throw ClassCastExeption
{code}
Root<A> root =...
Join<A,E> join = root.join(A_.e);
join.get(E_.attribute); <=== accessing any attribute of E will throw ClassCastExeption. With the following stack trace:\
{code}
{code}
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.AbstractPathImpl.get(AbstractPathImpl.java:189)
{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
11 years, 11 months
[Hibernate-JIRA] Created: (HHH-3644) Add support for "WITH UR" isolation clause on DB2
by Ricardo Fernandes (JIRA)
Add support for "WITH UR" isolation clause on DB2
-------------------------------------------------
Key: HHH-3644
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3644
Project: Hibernate Core
Issue Type: Sub-task
Components: core
Affects Versions: 3.3.1
Environment: HIbernate 3.3.1 / DB2 9.x
Reporter: Ricardo Fernandes
The question is basically the same as Steve's, i.e. to force DB2 to use as few locks as possible on heavy load scenarios.
Although some might consider the use of the WITH UR clause a bad approach (since it allows dirty reads), the fact is that there are some cases where this is in fact acceptable, such as computing the total amount of rows of a query (for information purposes) or producing a high-level listing of items with very little detailed info. The bottom line is: if I need to trade performance for extremely accurate data, I surely want to be able to decide when this should happen.
I've already performed the changes that makes it possible to use both the FOR READ ONLY and the WITH UR clauses and I will be submitting a patch shortly so you can have a look at it. The strategy I've used was basically the following:
1. Added two new methods on the Dialect class:
String getDatabaseReadOnlyString(String sql) - for adding the READ ONLY clause
String getDirtyReadsString(String sql) - for adding the WITH UR clause
2. Changed the Query interface in order to allow the user to say whether he/she wants the query to allow dirty reads:
Query setAllowDirtyReads(boolean allowDirtyReads);
3. Added a default implementation on the AbstractQueryImpl which initializes the flag a false
4. Added a similar attribute on the QueryParameters class
5. Changed the prepareQueryStatement() method of the Loader class (just after the useLimit part in order:
a) Ask the dialect for the getDatabaseReadOnlyString() is there are no LockModes set (as did Steve)
b) Ask the dialect for the getDirtyReadsString() is the queyParameters allows dirty reads.
All the tests were well succeeded.
Hope you find these changes, at least, worth looking at.
Best Regards,
Ricardo
--
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-3458) Register postgres random() function as "rand" in PostgresSQLDialect
by Stephen Cresswell (JIRA)
Register postgres random() function as "rand" in PostgresSQLDialect
-------------------------------------------------------------------
Key: HHH-3458
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3458
Project: Hibernate3
Issue Type: Improvement
Components: build
Affects Versions: 3.2.5
Environment: Postgres 8.3
Reporter: Stephen Cresswell
Priority: Trivial
I have an HQL query which uses "order by rand()". This works fine in our local integration tests (which are run against hsqldb), but fails against our build integration tests which runs postgres.
The reason the query fails is because postgres function for "rand" is called "random". We can workaround this by dynamically detecting the db driver and generating db specific queries, but it strikes me that the cleanest solution for this is to simply re-register postgres' random function as "rand" in the PostgresSQLDialect, i.e.
registerFunction( "random", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
registerFunction( "rand", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
--
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-6643) Criteria doesn't support a chaining of 2 not restrictions (sql = not not criterion)
by Lorber Sebastien (JIRA)
Criteria doesn't support a chaining of 2 not restrictions (sql = not not criterion)
-----------------------------------------------------------------------------------
Key: HHH-6643
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6643
Project: Hibernate Core
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.7
Environment: Oracle 10g
Hibernate 3.2.7
Reporter: Lorber Sebastien
Priority: Trivial
When we do:
"Restrictions.not( Restrictions.not( Restrictions.eq("field",3) ) );"
Hibernate generates
"where not not field=3"
Which generates an SQL exception
The correct SQL syntax is:
"where not (not field=3)"
(At least our Oracle)
I think Hibernate should handle such a case.
/!\
See org.hibernate.criterion.NotExpression#toSqlString
It seems that for MySQLDialect the parenthesis are added, but not for other dialects...
I don't know the sql specificities of all dialects but perhaps the parenthesis should be added also for oracle dialect?
Note that we use a custom dialect, extending Oracle10gDialect
For those interested: i'm doing two not on a criterion instead of using the criterion directly.
In real world, my code sample would be a little more complex: sometimes we compose with a lot of criterions, in many different methods.
So i do not exactly use Restrictions.not( Restrictions.not( criterion ) );
Trust me, bad luck, it happened that the dynamic composition of my restrictions, in one specific case, resulted on a double not restriction applied to a criterion.
Note that an easy workaround of this is to "add the parenthesis manually".
A conjunction is a bit like an "empty restriction" thus what i've done is:
Restrictions.not(
Restrictions.and(
Restrictions.not(
Restrictions.eq("field",3)
),
Restrictions.conjunction()
)
);
Adding the "not criterion" into conjunction containing only the criterion.
This way, the sql of my inner not restriction become something like:
( not field = 3 AND 1=1 )
-> We can apply a not on that, while we weren't able on "not field = 3"
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 11 months
[Hibernate-JIRA] Created: (HHH-7304) NaturalIdResolutionCache not correctly filled on first persist when @GeneratedValue-@Id
by Frank Schwarz (JIRA)
NaturalIdResolutionCache not correctly filled on first persist when @GeneratedValue-@Id
---------------------------------------------------------------------------------------
Key: HHH-7304
URL: https://hibernate.onjira.com/browse/HHH-7304
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 4.1.3
Reporter: Frank Schwarz
{code:title=Employee.java|borderStyle=solid}
@Entity
public class Employee{
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id;
@NaturalId(mutable = true) private String name;
@NaturalId(mutable = true) private String surname;
private String position;
}
{code}
{code:title=NaturalIdTest1.java|borderStyle=solid}
entityManager.getTransaction().begin();
Employee e = new Employee();
e.setSurname("Hans");
e.setName("Dampf");
e.setPosition("Junior");
entityManager.persist(e);
entityManager.getTransaction().commit();
Session session = entityManager.unwrap(Session.class);
Employee e2 = (Employee) session.byNaturalId(Employee.class)
.using("surname", "Hans")
.using("name", "Dampf")
.load();
System.out.println(e2);
{code}
{code:title=NaturalIdTest2.java|borderStyle=solid}
entityManager.getTransaction().begin();
Employee e = new Employee();
e.setSurname("Hans");
e.setName("Dampf");
e.setPosition("Junior");
entityManager.persist(e);
// this is the only difference
e.setPosition("Senior");
entityManager.getTransaction().commit();
Session session = entityManager.unwrap(Session.class);
Employee e2 = (Employee) session.byNaturalId(Employee.class)
.using("surname", "Hans")
.using("name", "Dampf")
.load();
System.out.println(e2);
{code}
The NaturalIdTest1 will issue an SQL statement for the find-by-natural-id-query; the NaturalIdTest2 does not.
Put a breakpoint into NaturalIdResolutionCache#cache(Serializable, Object[]) and watch the pk-parameter to be {{null}} on the first invocation and not {{null}} on the second invocation.
If the @Id-field is not @GeneratedValue, the first invocation of NaturalIdResolutionCache#cache will be already correct.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 11 months