-->
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.  [ 1 post ] 
Author Message
 Post subject: Unwrap potential issues
PostPosted: Tue Sep 15, 2015 9:30 am 
Newbie

Joined: Tue Sep 15, 2015 7:39 am
Posts: 1
Hi,

I need to execute plain SQL query inside an ejb 3 service method (for example I need to get data from some technical oracle tables), my strategy was the following:

Get a plain jdbc connection

Code:
   private Connection getConnection() {
      org.hibernate.Session hibernateSession = entityManager.unwrap(org.hibernate.Session.class);
      final Connection[] connections = new Connection[1];
      hibernateSession.doWork(connection -> connections[0] = connection);
      return connections[0];
   }


ejb method:

Code:
public String doStuff() throws MyException{
SomeKindOfManagedObject o = new SomeKindOfManagedObject()
entityManager.persist(o)

//business logic
//modification to object "o"

final Connection connection = getConnection();
String query = "select * from all_tab_partitions where table_name = '"+ MY_TABLE +"'";
try (final Statement statement = connection.createStatement()) {
      final ResultSet rs = statement.executeQuery(query);
      doSomeKindOfStuff(rs);
}catch(Exception e){
      logger.log(e);
      throw new MyException(e);
}

entityManager.merge(o);

}




are there some kind of potential hidden issues related to unwrapping and using a plain jdbc connection as I did?

Is it tricky to mix ORM operation and plain JDBC query as I did?

Thanks!


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

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.