-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Name clash implementing Session
PostPosted: Tue Dec 06, 2016 8:01 pm 
Newbie

Joined: Tue Dec 06, 2016 7:31 pm
Posts: 3
The interface org.hibernate.Session extends SharedSessionContract and EntityManager. SharedSessionContract extends QueryProducer.

EntityManager has:

Query createNativeQuery(String var1, Class var2);

QueryProducer has:

<R> NativeQuery<R> createNativeQuery(String var1, Class<R> var2);

These two methods have the same erasure and so implementing the interface Session has so far been impossible. Obviously, it can be done, but I would really appreciate it if someone could explain how.

Thank you,

Donald


Top
 Profile  
 
 Post subject: Re: Name clash implementing Session
PostPosted: Wed Dec 07, 2016 4:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
As demonstrated by Hibernate 5.2, this works because org.hibernate.query.NativeQuery extends javax.persistence.Query.

Therefore, both the following queries are valid:

Code:
NativeQuery nativeQuery = entityManager
    .unwrap( Session.class )
    .createNativeQuery( "select * from DateEvent", DateEvent.class );

Query query = entityManager
    .createNativeQuery( "select * from DateEvent", DateEvent.class );


Top
 Profile  
 
 Post subject: Re: Name clash implementing Session
PostPosted: Wed Dec 07, 2016 9:35 am 
Newbie

Joined: Tue Dec 06, 2016 7:31 pm
Posts: 3
Interesting, but not helpful. That explains why it can work, but not how to make it work. I've tried many approaches to declaring createNativeQuery, but everything I've tried so far gets a syntax error of one kind or another. What would a valid declaration for createNativeQuery actually look like?


Top
 Profile  
 
 Post subject: Re: Name clash implementing Session
PostPosted: Wed Dec 07, 2016 9:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Why do you want to implement the Hibernate Session anyway? What's your use case?


Top
 Profile  
 
 Post subject: Re: Name clash implementing Session
PostPosted: Wed Dec 07, 2016 10:00 am 
Newbie

Joined: Tue Dec 06, 2016 7:31 pm
Posts: 3
It's a mock as part of my unit testing. It has worked fine for me up until I tried to update from 5.0.5 to 5.2.5.


Top
 Profile  
 
 Post subject: Re: Name clash implementing Session
PostPosted: Wed Dec 07, 2016 10:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Check out this Unit Test from hibernate-infinispan module. It works just fine on the master branch (5.2.5).

The test mocks the Hibernate Session without any issue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.