-->
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.  [ 7 posts ] 
Author Message
 Post subject: Working with Hibernate inside a Stateless Session Bean
PostPosted: Sat Dec 03, 2005 3:18 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Hibernate version:3.1rc3

I am looking for some pointers on using Hibernate inside a Stateless Session Bean. I have written, deployed and tested some code with Hibernate 3.1.

I need to expose this through a Session Bean. Is it as easy as something like below...

public class MySessionBean ...
{

// Session call backs that need to be added from the
// implemented interfaces.

...

// My business method that will use the Hibernate code
public void submit(String fName, String lName)
{
Session s = HibernateUtil.getSession();

// Get a transaction object here

// Finally create and save the Person via Hibernate
Person p = new Person();
p.setFirstName(fName);
p.setLastName(lName);
s.save(p);
// rest of hibernate code...
}

}

Ofcourse there is other stuff, like throws clauses etc...

I just wanted to see if this would get me the needed Hibernate Session to save a person object via Hibernate.

Any caveats? Anything I am missing?

Thank You.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 7:22 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Wrong HibernateUtil, http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 10:44 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Wrong HibernateUtil?

But right idea?


I wasn't trying to get caught up in the specifics of HibernateUtil just yet.

I was just wondering if this was the correct approach.

1) Get a hibernate session object.
2) Get a Transaction object.
3) Instantiate and set your Hibernate beans members.
4) session.save and tx.close

Sorry for anything misleading that I may have done before.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 11:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 11:42 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Good lord Christian! ( As in "Come on dude!" =) )

You are making me feel like I am back in college and you are my professor refusing to answer a yes/ no question. =)


Ok I get it. You are gonna tell me to go look it up. And let me figure it out for myself if I understand it. =)


BTW, I will take this chance, since I have your attention. If you are the Christian that is a co-author of Hibernate in Action. Many thanks to you and Gavin for writing such a great book. It's an easy read, concise and to the point. Almost like reading a short thriller novel. Ok, maybe not that exciting, but you get my point.

When if ever, can we expect an updated version for Hibernate 3.x?

Thanks for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 11:48 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://caveatemptor.hibernate.org/


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 11:58 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
christian wrote:
http://caveatemptor.hibernate.org/


hehehe, thanks and have a nice weekend.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.