[Hibernate-JIRA] Created: (HHH-6902) Create typed query in EntityManager throws NullPointerException when filters are present
by Dan Luca (JIRA)
Create typed query in EntityManager throws NullPointerException when filters are present
----------------------------------------------------------------------------------------
Key: HHH-6902
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6902
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 4.0.0.Final
Environment: Oracle 11g; HibernateCore 4.0.0.Final; Spring 3.1.0
Reporter: Dan Luca
I have an environment with JPA annotated entities, some with filters - e.g. filter out logically deleted entities. I have upgraded to hibernate 4 and discovered that {{javax.persistence.EntityManager.createQuery(String, Class<T>)}} throws a {color: red}NullPointerException{color} every time is invoked.
I did some digging and here is what I have found:
* calling {{entityManager.createQuery("query", resultType)}} on the current entity manager, ends up at {{org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(String, Class<T>)}}
* this method does two things:
*# creates the actual HQL query
*# performs validation of the result type
* step 2 above has the following call
{code:title=AbstractEntityManagerImpl}
final HQLQueryPlan queryPlan = unwrap( SessionImplementor.class )
.getFactory()
.getQueryPlanCache()
.getHQLQueryPlan( jpaqlString, false, null );
{code}
Note the third argument in the {{QueryPlanCache.getHQLQueryPlan(String, boolean, Map)}} call is null. This argument is a raw +Map+ of enabled filters.
* {{org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(String, boolean, Map)}} implementation creates a cache key from {color:navy}(queryString, shallowFlag, enabledFilters){color} tuple and if a plan exists it uses it, otherwise creates a brand new plan by invoking its constructor: {{new HQLQueryPlan(queryString, shallow, enabledFilters, factory )}}
** Note that the key created by step 1 above when there are filters defined, is +different+ from the one created with {{enabledFilters}} set to empty or null
* the HQLQueryPlan constructor invokes *{color:red}{{enabledFilters.keySet()}}{color}* - hence the NPE
I believe the correct invocation of the {{getHQLQueryPlan()}} at step 2 - for the purposes of validation - should be something like this instead:
{{.getHQLQueryPlan( jpaqlString, false, *Collections.emptyMap())*}}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 12 months
[Hibernate-JIRA] Created: (HHH-6593) Fetch joining subelements of a one-to-one or many-to-one association
by Christian Beikov (JIRA)
Fetch joining subelements of a one-to-one or many-to-one association
--------------------------------------------------------------------
Key: HHH-6593
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6593
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.6
Reporter: Christian Beikov
Priority: Critical
The problem is discussed on the forum a long time ago. I just found the topic and i wanted to report that this bug is still available in 3.6.6
https://forum.hibernate.org/viewtopic.php?f=1&t=987905&start=0
Here a concrete example from my usecase:
class A{
private B b;
}
class B{
private Map<String, C> map;
}
class C{
private String c;
}
Just imagine that the classes and fields would be annotated right ;)
Now the problem in my case was that i wanted a list of A elements with fetch joined B and of course it's map.
I tried the following query:
FROM A a LEFT OUTER JOIN FETCH a.b bElem LEFT OUTER JOIN bElem.map cMap
and i got a NullPointerException just like the users which posted in the given topic.
My workaround was:
FROM A a LEFT OUTER JOIN FETCH a.b bElem LEFT OUTER JOIN a.b.map cMap
The main problem now is, that i have a dynamic fetch profile system which won't work correctly if this issue is not solved.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 12 months
[Hibernate-JIRA] Created: (HHH-6695) Error "Cannot create TypedQuery for query with more than one return" with named queries
by Oliver Siegmar (JIRA)
Error "Cannot create TypedQuery for query with more than one return" with named queries
---------------------------------------------------------------------------------------
Key: HHH-6695
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6695
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 4.0.0.CR4, 3.6.7, 3.6.8
Reporter: Oliver Siegmar
The already closed issues HHH-5348 and HHH-6591 only fixed the bug with standard (non-named) queries. Having a query like {code:sql}SELECT NEW org.test.MyClass( 'Foo', 123 ) FROM IrcEvent ev{code} as shown in HHH-6591 used by createQuery(), the bug has been fixed. Using the very same query as a named query by createNamedQuery() this exception is thrown:
{noformat}
java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return
at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:684) ~[hibernate-entitymanager-4.0.0-20110929.060732-144.jar:4.0.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0]
...
{noformat}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 12 months
[Hibernate-JIRA] Created: (HHH-6963) Criteria generates incorrect sql: ManyToMany w additional columns
by Marc Schipperheyn (JIRA)
Criteria generates incorrect sql: ManyToMany w additional columns
-----------------------------------------------------------------
Key: HHH-6963
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6963
Project: Hibernate ORM
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.6.9, 3.6.8
Reporter: Marc Schipperheyn
Priority: Minor
Referencing forum https://forum.hibernate.org/viewtopic.php?f=1&t=1014117
Criteria generates the wrong sql with a ManyToMany with an intermediary class with extra columns using AssociatonOverride for an embeddedId.
Using hql, the correct sql is generated
select this_.candidateId as candidat2_28_0_, this_.networkId as networkId28_0_, this_.remove as remove28_0_ from NetworkCandidates this_ where ***network2_***.networkId=? and ***candidate3_***.candidateId=?
it should be
select this_.candidateId as candidat2_28_0_, this_.networkId as networkId28_0_, this_.remove as remove28_0_ from NetworkCandidates this_ where ***this_***.networkId=? and ***this_***.candidateId=?
Class configuration:
@Entity
@Table
@AssociationOverrides({
@AssociationOverride(name = "pk.network",
joinColumns = @JoinColumn(name = "networkId")),
@AssociationOverride(name = "pk.candidate",
joinColumns = @JoinColumn(name = "candidateId"))
})
public class NetworkCandidateLink implements Serializable{
private NetworkCandidateLinkId pk = new NetworkCandidateLinkId();
private boolean remove=false;
public NetworkCandidateLink(){}
public NetworkCandidateLink(Network network, NetworkCandidate candidate){
pk.setCandidate(candidate);
pk.setNetwork(network);
}
@EmbeddedId
public NetworkCandidateLinkId getPk() {
return pk;
}
public void setPk(NetworkCandidateLinkId pk) {
this.pk = pk;
}
}
@Embeddable
public class NetworkCandidateLinkId implements Serializable{
private Network network;
private NetworkCandidate candidate;
@ManyToOne(optional=false)
public NetworkCandidate getCandidate() {
return candidate;
}
public void setCandidate(NetworkCandidate candidate) {
this.candidate = candidate;
}
@ManyToOne(cascade=CascadeType.MERGE,optional=false)
public Network getNetwork() {
return network;
}
public void setNetwork(Network network) {
this.network = network;
}
}
@Entity
@Table
public class Network implements Serializable{
private Long id;
private Set<NetworkCandidateLink> candidates;
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="pk.network")
@Fetch(FetchMode.SELECT)
public Set<NetworkCandidateLink> getCandidates() {
return candidates;
}
}
@Entity
@Table
public class NetworkCandidate implements Serializable {
private Long id;
private List<NetworkCandidateLink> networks;
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="pk.candidate")
public List<NetworkCandidateLink> getNetworks() {
return networks;
}
}
Criteria:
return (NetworkCandidateLink) this.getSessionFactory().getCurrentSession().createCriteria(NetworkCandidateLink.class)
.createAlias("pk", "pk")
.createAlias("pk.network", "network")
.createAlias("pk.candidate", "candidate")
.add(Restrictions.eq("network.id", networkId))
.add(Restrictions.eq("candidate.id", candidateId))
.uniqueResult();
HQL:
String hql = "from NetworkCandidateLink ncl inner join ncl.pk.network network inner join ncl.pk.candidate candidate where candidate.id=:candidateId and network.id=:networkId";
return (NetworkCandidateLink) this.getSessionFactory().getCurrentSession().createQuery(hql)
.setParameter("networkId", networkId)
.setParameter("candidateId", candidateId)
.uniqueResult();
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 12 months
[Hibernate-JIRA] Created: (HHH-5275) Criteria.setLockMode does not work correctly
by Björn Moritz (JIRA)
Criteria.setLockMode does not work correctly
--------------------------------------------
Key: HHH-5275
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5275
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.2
Environment: Hibernate 3.5.2, Oracle 10 (using org.hibernate.dialect.Oracle10gDialect
Reporter: Björn Moritz
Priority: Minor
Attachments: TestCase.zip
The LockMode set via Criteria.setLockMode does not generate a ' for update' SQL statement. In the org.hibernate.dialect.Dialect class only the LockOptions are used for determining a possible addition to the SQL statement if using pessimistic locking. This behaviour is different from Hibernate 3.1.3.
In the supplied TestCase two threads are reading the same database record; one of those threads should use pessimistic locking thereby blocking the other thread. But both threads can read the database record causing the test to fail.
--
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
12 years, 12 months