-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with ejb and hibernate as a service
PostPosted: Tue Nov 11, 2003 5:48 pm 
Newbie

Joined: Tue Nov 11, 2003 5:38 pm
Posts: 2
hi, i have hibernate working as service in jboss, just like it is explainded in http://www.hibernate.org/66.html . It is working fine, but now i want to create a session bean and use the service, but i get errors and i dont know how to fix it, thats the example of the bean (i've made it whit lomboz plugin for eclipse) . I've read all docs i found, but i can't make it work if somebody could fix that class or publish a similar working exmple i'll be very glad

TIA

/*
* Created on Nov 10, 2003
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.droplabs;

import javax.ejb.SessionBean;
import javax.naming.*;
import java.util.*;
import net.sf.hibernate.*;


/**
* @ejb.bean name="Hib"
* jndi-name="HibBean"
* type="Stateless"
**/

public abstract class HibBean implements SessionBean {

/**
* @ejb.interface-method
* tview-type="remote"
**/
public String setProducto(String product_id){
Properties p = new Properties();

//The JNDI properties you set depend
//on which server you are using.
//These properties are for the Remote Server.
p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.provider.url", "127.0.0.1");
p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

Context ctx = new InitialContext(p);
SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/HibernateFactory");
Session sess = factory.openSession();

Transaction transaction = sess.beginTransaction();

/* HERE IS WHER I HAVE THE ERROR, OBVIOUS I DON'T HAVE REFERENCES TO PRODUCT CLASS */
Product princess = new Product();
princess.Product("Princess");
sess.save(princess);
transaction.commit();
sess.close();
return "ok";
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 5:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The EJB is deployed using the usual jar in the deploy directory. The sar is already present so the domain objects should be found no problem as its the same deployment service. The link you quoted has a link to an example which should provide some guidence otherwise there is not enough information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 6:08 pm 
Newbie

Joined: Thu Oct 09, 2003 11:11 am
Posts: 5
What is the exception?

If deploying as a service, you actually tell the hibernate service where to find a user transaction on jndi.

SO, your EJB config would need BMT for this one to work.

If you are using CMT, then you must have required transaction on the ejb methods for anything to work.

for xdoctags - i think it is something like

ejb.transaction type="Required"


Top
 Profile  
 
 Post subject: Problem
PostPosted: Wed Nov 12, 2003 5:05 pm 
Newbie

Joined: Tue Nov 11, 2003 5:38 pm
Posts: 2
Eclipse shows that error and doesn't compile

Product cannot be resolved or is not a type HibBean.java test/src/com/droplabs line 44


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