-->
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.  [ 14 posts ] 
Author Message
 Post subject: jboss jndi error with session bean to wrap hiberenate jndi
PostPosted: Sun Nov 30, 2003 10:58 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear all,

Sorry for posing this topic again, especially to Hibernate team as I still could not resolve the factory jndi issues

Using the advice provided, thel following erros again appears on the jboss jndi look up through local client and session bean jndi wrap up



{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.provider.url=localhost:1099, jnp.timeout=0, jnp.socketFactory=org.jnp.interfaces.TimedSocketFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces, jnp.sotimeout=0}
RelHome
RelHome
home1=RelHome
0 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - deserializing
30 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - deserialized: 4028819af92fa8af00f92fa8b3cb0000
30 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - Resolving serialized SessionFactory
30 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
50 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - lookup: uid=4028819af92fa8af00f92fa8b3cb0000
50 [AWT-EventQueue-0] WARN net.sf.hibernate.impl.SessionFactoryObjectFactory - Not found: 4028819af92fa8af00f92fa8b3cb0000
50 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - {}
50 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - lookup: name=java:/HibernateFactory
50 [AWT-EventQueue-0] WARN net.sf.hibernate.impl.SessionFactoryObjectFactory - Not found: java:/HibernateFactory
50 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - {}
java.lang.reflect.UndeclaredThrowableException
at $Proxy1.HiberData(Unknown Source)
at javaPrg.MSSC_MENU.GetCon2(MSSC_MENU.java:575)
at javaPrg.MSSC_MENU$3.actionPerformed(MSSC_MENU.java:128)

-----------------------------------------------------------------

Caused by: java.io.InvalidObjectException: Could not find a SessionFactory named: java:/HibernateFactory
at net.sf.hibernate.impl.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:393)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)


----------------------------------------------------------------------------------

jboss log out indicate jndi successfully bond


10:40:36,193 INFO [TxConnectionManager] Started jboss.jca:service=LocalTxCM,name=PostgresDS
10:40:36,193 INFO [HibernateServiceMBean] starting service at JNDI name: java:/HibernateFactory
10:40:36,193 INFO [HibernateServiceMBean] service properties: {hibernate.session_factory_name=java:/HibernateFactory, hibernate.transaction.manager_lookup_class=net.sf.hibernate.transaction.JBossTransactionManagerLookup, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.show_sql=true, hibernate.use_outer_join=false, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory, hibernate.connection.datasource=java:/PostgresDS}
10:40:36,353 INFO [Environment] Hibernate 2.1 rc1
10:40:36,383 INFO [Environment] hibernate.properties not found
10:40:36,413 INFO [Environment] using CGLIB reflection optimizer
10:40:36,423 INFO [Configuration] Mapping resource: src/grp.hbm.xml
10:40:37,124 INFO [Binder] Mapping class: src.grp -> grp
10:40:37,525 INFO [Configuration] Mapping resource: src/codemaster.hbm.xml
10:40:37,625 INFO [Binder] Mapping class: src.codemaster -> codemaster
10:40:37,635 INFO [Configuration] processing one-to-many association mappings
10:40:37,635 INFO [Binder] Mapping collection: src.grp.codemaster -> codemaster
10:40:37,645 INFO [Configuration] processing one-to-one association property references
10:40:37,645 INFO [Configuration] processing foreign key constraints
10:40:37,745 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
10:40:37,745 INFO [SettingsFactory] Use outer join fetching: false
10:40:37,775 INFO [NamingHelper] JNDI InitialContext properties:{}
10:40:37,795 INFO [DatasourceConnectionProvider] Using datasource: java:/PostgresDS
10:40:37,815 INFO [TransactionFactoryFactory] Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
10:40:37,825 INFO [NamingHelper] JNDI InitialContext properties:{}
10:40:37,845 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
10:40:37,865 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
10:40:37,865 INFO [NamingHelper] JNDI InitialContext properties:{}
10:40:37,865 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
10:40:37,865 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
10:40:40,619 INFO [SettingsFactory] Use scrollable result sets: true
10:40:40,619 INFO [SettingsFactory] JDBC 2 max batch size: 15
10:40:40,629 INFO [SettingsFactory] echoing all SQL to stdout
10:40:40,629 INFO [SettingsFactory] Query language substitutions: {}
10:40:40,629 INFO [SettingsFactory] cache provider: net.sf.ehcache.hibernate.Provider
10:40:40,659 INFO [Configuration] instantiating and configuring caches
10:40:41,080 INFO [SessionFactoryImpl] building session factory
10:40:41,961 INFO [SessionFactoryObjectFactory] Factory name: java:/HibernateFactory
10:40:41,961 INFO [NamingHelper] JNDI InitialContext properties:{}
10:40:41,961 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/HibernateFactory
10:40:41,971 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
10:40:41,971 INFO [NamingHelper] JNDI InitialContext properties:{}


partioal Rel session bean look up to test the factory look up only


try {
Context ctxh = new InitialContext();
Hashtable env = ctxh.getEnvironment();
Object oHiber;

oHiber = ctxh.lookup("java:/HibernateFactory");

//factory=(SessionFactory)PortableRemoteObject.narrow(oHiber,SessionFactory.class);
SessionFactory factory = (SessionFactory) oHiber;
System.out.println("factory= " + factory);
harr.add(factory);

session = factory.openSession();
tx = session.beginTransaction();
}

//---- catch exception errors

---------------------------------------------------

partial client session bean look up procedure

public void GetCon2() {
try {
Context ctx1 = new InitialContext();
env = ctx1.getEnvironment();

Object oRef1;
Object oRef2;

System.out.println(env);
oRef1 = ctx1.lookup("Rel");
System.out.println(oRef1);


System.out.println(oRef1);

RelHome home1 = (RelHome) PortableRemoteObject.narrow(oRef1,
RelHome.class);
System.out.println("home1=" + home1);
Rel remote1;
remote1 = home1.create();
System.out.println("result=" + remote1.HiberData());
}///
etc ....

What I am interested now is whether using local client programme to look up
a hibernate jndi wrapped inside a stateless session bean is in fact a proper way to perfrom the java:/HibernateFactory jndi deployed using SAR





Thanks


Top
 Profile  
 
 Post subject: complicating it?
PostPosted: Sun Nov 30, 2003 11:45 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
A cleaner approach is to make one class to use that hides the hibernate implementation from your other classes. A simple class that, once you give it your query/load/save command and the required parameters, it does the rest and catches all the errors. That lets you distance yourself from your database layer even more (a facade) and say things like:

eg.DB db = new eg.DB(); // my class to handle hibernate calls
db.save(item, someSerializableKey);
OR
db.query(queryString, parameters[]);

I do this and it saves me a lot of headaches. When the new eg.DB() is called, it does the JNDI lookups and opens the session for me. If transactions are required, my function is setup to do them automatically. It's all out of my sight: hidden and nice & clean. No need to code those Hibernate calls and lookups in every servlet/cgi/sub-application. Just tell your DB class to do it for you and never look back.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 12:17 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear David,


Thanks for your advice, what i can understanding from your suggestion is , I must create a seperate class to look for the JNDI and so on and so for , but my understand from the reply from Gavin is that that "it must exist within the same JVM" .


Please correctly if I am wrong on the following interpretation:

I think I would definitely run into hiberateFactory not bound
sort of error if I choose the above approach
Without the jboss jndi approach , I have success with those conventional method using xml or user provide JDBC but things turn out that something is really wrong on my approach to jboss jndi SAR implemented mbeans.


I guess my earlier approach using session bean is not workable . could your be more specific on the advice on " When the new eg.DB() is called, it does the JNDI lookups and opens the session for me."

What is on my mind at the moment is hibernate jndi is a bit similar to EJB local interface where you can not call them externally or remotely , in the case of EJB , I usually wrapped it with local interface using a session bean to perform the jndi look up.

despite all the example provide by you and your team with so much kindness and toughtful as it seems , I am y sad to admit that a fool like me whose deeply incardinated with EJB concept just could not get hold of the HIBERNATE jndi object mapping concept with SAR & JNDI approcah .


Top
 Profile  
 
 Post subject: jndi
PostPosted: Mon Dec 01, 2003 1:26 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Dear tsg26 (do you have a name? *grin*),

I believe you said you were using JBoss, so my explanations go with it as a point of reference. Gavin mentions the 'same JVM' when talking about JNDI because a hibernate SessionFactory. He essentially means that
a Hibernate SessionFactory cannot be passed between JBoss instances or across different servers like EJB. A SessionFactory is not serializable like an EJB.

So, if you have a server farm, you cannot do a remote JNDI lookup on another server's JBoss and get a session from that server. You must have a hibernate SessionFactory configured and running within each JBoss instance.

Data sources, on the other hand, can refernce databases on different servers as well as on different database products. That is one of the wonderful benefits of hibernate. Multiple session factories can be setup so various objects can reside on different databases or database servers. JDBC and hibernate take care of that for you.

Now, with your approach, I see nothing wrong with it as long as you are not making an EJB session bean for a server farm that needs to use hibernate. If so, you need to review the documentation on the www.hibernate.org site (or other hibernate forum threads/topics) to see how other people handle mixing EBJ, multiple JBoss servers, and hibernate. Again, it matters if you are a one-JBoss environment or a server farm with multiple JBoss enviroments and need EJB.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 1:47 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear David,

Thanks for your compliments

You can called me Eric , I do gain lot and got some point regarding hibernate JNDI issue.

Well I think and it is my fault that I do miss out a very important point is that I run a single JBOSS under eclipse 3 environment , constructing a standalone client under eclipse as well to look up for the hibernate JNDI employ as SAR , perfoming processing through session beans .

Would the above scenario fit under the situation "
it matters if you are a one-JBoss environment or a server farm with multiple JBoss enviroments and need EJB. "

I am not very sure on that point , could you elaborate and confrim my scenario please. As for my case , I only deploy one jboss application server under LAN environment , all the programme coding are perform on the same JBOSS application server too but under the shielding of Eclipse,in that respect , I may be discounted from the server farm issue , but may or may not comply with same JVM principle.


Kindly help me to resolve the issue once again please, would you suggest that I should uninstall everything and start all over again just in case something perhaps jar got corrupted and causing all the hardship.

I really feel sorry and aplogised for posing query and revolve over and over again on these JNDI issue.




Thanks

Eric


Top
 Profile  
 
 Post subject: Eclipse/JBoss
PostPosted: Mon Dec 01, 2003 2:38 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Eric,

By server farm, I mean a production environment composed of multiple JBoss web servers. It sounds like you have one JBoss server for production and probably one only instance of JBoss running on it.

You should check this but your development Eclipse probably starts it's own copy of JBoss. This is how it (Eclipse) runs Tomcat for me (in a new JVM). This allows Eclipse to get it's debugging hooks into the application server. Yours is probably doing this.

Why is that a good thing? Yes. Then your JNDI calls would be local to that development instance of JBoss. This would allow you to use a different JNDI SessionFactory than production so you can have a test database and not worry about possibly disrupting production when you create/alter data during your testing. With that in mind, when you DO migrate the system to production, make sure you edit your hibernate.cfg.xml (or hibernate.properties if you use that) file to include the appropriate production JDBC url and username/password so production's hibernate uses the production database, not your test database. :)

Good night and good luck.

Regards,
David

P.S. If you have other questions on this topic, I'm sure posting a reply will get wonderful responses from some saavy hibernate programmers in an 'awake' part of the world. :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 5:40 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear David,

I got the following messages from the jboss log output , where the harr is the ArrayList return from the session bean indicating the sql works and at least something for the session factory

[b]17:39:03,100 INFO [STDOUT] factory= net.sf.hibernate.impl.SessionFactoryImpl@1c047f0[/b]17:39:04,111 INFO [STDOUT] Hibernate: select grp0_.grpcode as grpcode, grp0_.grpdesp as grpdesp from grp grp0_ limit ?
17:39:04,602 INFO [STDOUT] harr =[net.sf.hibernate.impl.SessionFactoryImpl@1c047f0]


But
I could not understand the following errors from Eclipse


{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.provider.url=localhost:1099, jnp.timeout=0, jnp.socketFactory=org.jnp.interfaces.TimedSocketFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces, jnp.sotimeout=0}
RelHome
RelHome
home1=RelHome
0 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - deserializing
20 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - deserialized: 4028819af93126a000f93126a4f40000
30 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - Resolving serialized SessionFactory
30 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
60 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - lookup: uid=4028819af93126a000f93126a4f40000
60 [AWT-EventQueue-0] WARN net.sf.hibernate.impl.SessionFactoryObjectFactory - Not found: 4028819af93126a000f93126a4f40000
60 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - {}
60 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - lookup: name=java:/HibernateFactory
60 [AWT-EventQueue-0] WARN net.sf.hibernate.impl.SessionFactoryObjectFactory - Not found: java:/HibernateFactory
60 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - {}


[b]java.io.InvalidObjectException: Could not find a SessionFactory named: java:/HibernateFactory[/b] at net.sf.hibernate.impl.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:393)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:925)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1655)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.util.ArrayList.readObject(ArrayList.java:547)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:136)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:100)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy1.HiberData(Unknown Source)
at javaPrg.MSSC_MENU.GetCon2(MSSC_MENU.java:583)
at javaPrg.MSSC_MENU$3.actionPerformed(MSSC_MENU.java:130)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


Could anybody provide guidance and advice please!

Thanks
ERIC


Top
 Profile  
 
 Post subject: suggestion
PostPosted: Mon Dec 01, 2003 6:43 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Have you tried changing your JNDI from 'java:/HibernateFactory' to one level removed 'java:/hibernate/HibernateFactory' in case it needs to create the context? Also, is the 'java:/XXXX' read-only? Could that be your problem? Can you make up a new name instead of 'java:'? Everything else looks (very strange but) in order from your code segments.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 7:36 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear MIT David,


I am not sure what are you trying to tell me, just for your info the SAR files was deployed into the jboss deploy directory in order to run under JMX and installed as mbeans. I don't think it got something to do with the attribute of the JNDI context. As for your suggestion regarding the java:/hibernate/HibernateFactory , I prefer to stick with AUS David suggestion of naming using java convention java:/HibernateFactory as I got bad experience with the subcontext JNDI.




Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 4:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Can you create a very very simple package that I can compile up and test for you. This should have been easy to sort out.

sebd it to: david@hibernate.org


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Had a look at the code: Use CMT for the SLSBs and thus don't create your Transactions (see the examples I sent you), you have not set the user user transaction JNDI setting and this is why the JNDI lookup failed. This is not a problem if you just let the container do the transaction demarcation for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 7:23 pm 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Dear David,


I really appreciate you sincere effort and yours persistence guidance,helfulness and caring attitude that you have shown and set as an example over in this forum on helping peolple epecially towards the newbies .

For the benefit of others and on open source sharing principle , I would seek your understanding and permission to allow me to reproduce your explanation towards the issue at this forum

---------------------------------------------------------------------------------



Had a quick look at the code. I cannot run it etc as such but I had a
look anyway. I hope the examples are not formatted oddly by the email
client.
Here are my comments.

I was glad to see your not (no longer) trying to access the system from
the GUI via JNDI (It will never work).
So here is what I would try:
1) I assume you have confirmed you do get into the SLSB from the swing
client (make sure you can).
2) Break some of the code into small utility functions so it can be much
cleaner (it is a bit of a mess at the moment).
For example here an example of the JNDI lookup.

public class HibernateUtil {

public static SessionFactory getHibernateSessionFactory() throws
NamingException
{
InitialContext initialContext = new InitialContext();
try {
SessionFactory factory = (SessionFactory)
initialContext.lookup("java:/HibernateFactory");
return factory;
}
finally {
initialContext.close();
}
}
}


3) Use CMT for the SLSB which simplifies the transaction management, eg,
don't need to do any. For example.

public boolean isUserValid(String UserName, String Password) {
Session sess = null;
boolean result = false;
try {
sess = HibernateUtil.openSession(this.factory);
result = authDAO.isUserValid(UserName, Password);
sess.flush();
}
catch (Exception e) {
ctx.setRollbackOnly();
throw ExceptionAdapterUtil.createExceptionAdapter(e);
}
finally {
HibernateUtil.closeSession(sess);
}
return result;
}

Where ctx is the SLSB context attribute, the factory is returned set when
the SLSB is created by the utility function above. The utility functions for
the session creates it and places the session into a Thread local for access
by the DAO layer. You may not need this so the DAO becomes you operations
and you open and close the session as normal from the session factory.
You can see there is not start transaction or commit. Not needed let the
container do the work for you. If you really want this then you will need to
define the user transaction JNDI entry in your SAR service description. This
is the JNDI lookup the is failing. Use CMT only and it is likely it will
work.

Finally you service description should not leave any spaces in the
definition, eg, don't have the <attribute> tags on there own lines. I have
found that sometime problems occur if you do this (depends on the Hibernate
version how tolerant it is).

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService"
name="jboss.jca:service=HibernateFactory, name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<depends>jboss.jca:service=LocalTxCM,name=PostgresDS</depends>
<attribute name="MapResources">src/grp.hbm.xml,
src/codemaster.hbm.xml</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/PostgresDS</attribute>
<attribute
name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute>
<attribute
name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactor
y</attribute>
<attribute
name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTr
ansactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">true</attribute>

</mbean>
</server>

Good luck,

Cheers David,


--------------------------------------------------------------------------------------

Just side track a bit , supposing a seperate jar files or class files have been employed using the SAR , how would one make use of the existing class packaged in the SAR through JMX ? what on my mind right now is , if I could successfully look up the factory , would it be a better approach to adopt where having some CMP or BMP transactions embedded within the session bean such as casting of hiebernate class involving get method


Thanks


ERIC


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 7:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Eric,

Your most welcome and thank you for your positive comments. We are all learning so helping each other is a way for us all to grow.

Your questions I am not sure what you are asking. The JBoss deployer will put all of the packages into the classpath so they are avaiable for use by the application. If you separate some layers, eg, servlets into different VMs then you will need to include the jars on both deployment packages. Wish you well with your efforts.

Cheers David.


Top
 Profile  
 
 Post subject: Guide on using hibernate JDNI factory with JBOSS
PostPosted: Thu Dec 04, 2003 3:34 am 
Beginner
Beginner

Joined: Fri Nov 28, 2003 3:45 am
Posts: 23
Location: malaysia
Hello,

Posted here are some of advice and experience that I would like to share after having a very stiff learning curve going through the JBOSS jndi deployed using SAR.

To look up JNDI, one should do it within the SAME JVM for example if the session bean is employed, create a simple procedure or class suggested by David to perform the look up within the session bean class.

In my case , I defined the a simple JNDI method in the session bean, variables for factory , session,transaction as global so that it could be easily accessible by all the method within the Session Bean.

To open up a new session try the following
session = this.factory.openSession()
after having call the method that Lookup the hibernate JNDI factory.
The rest of normal transaction will then be proceed as usual.

The mapping classes use by the SAR must also implements Serializable to avoid possible errors during execution.

If there is a need to cast certain class in order to perform the getXXX()
defined within the SAR , the solution that work for me is to define or package the same class to be included in the session bean as what has been defined or packaged with the SAR.

For example src.eg.X is the mapping class for SAR , the same src.eg.X must also be packaged and stored in the EJB ear file or war file.

I am not very sure whether there are any alternative ways to directly obtained the required class from the SAR, so that class required by the session bean needed for get XXor setXX casing could be achieved . If anyone of you got the solution , kindly contribute .


I do hope the above explanation would serve as a steeping stone for those initial venture into the JBOSS SAR with hibernate.


Thanks



























[size=18][/size]


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