and when ever I need to persist or remove I am doing this each and every time EntityManagerFactory emf =Persistence.createEntityManagerFactory("usermgt");
Give me some sugessions so that I can use this commonly. I am using weblogic9.2.
I need to read the database properties from a configurable properties file and set to the persistance.xml how can I do this for example if I need to change the database I need to go to persistance.xml and need to change the values, but I need like there should be a properties file in that I need to configure all the database properties and need to access those values to persistance.xml how can I do this?
The whole porperties and persistence.xml can all be done through code too, if you really want to have flexibility like that without having to rebuild each time.
Mark
Pramod Kumar
Ranch Hand
Joined: Oct 05, 2007
Posts: 40
posted
0
I am getting exception while using jta-data-source
I am using Weblogic 9.2, I have created a DataSource with the name UserDs with all the properties in Weblogic and I gave that datasource name in jta-data-source I am getting the exception as shown below.
javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27) at entity.PersonTest.initEmfAndEm(PersonTest.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
--------------
1937 [main] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{} 1953 [main] FATAL org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: OamDs javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284) at javax.naming.InitialContext.lookup(InitialContext.java:351) at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
1937 [main] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{} 1953 [main] FATAL org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: OamDs javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an
So either you need to include a jndi.properties file in your app, or the app server needs one.
Mark
Pramod Kumar
Ranch Hand
Joined: Oct 05, 2007
Posts: 40
posted
0
I have created jndi.properties file in class path and I have given the properties in it.
and in the code I have given as below but still I am getting the same exception. Do I need to code any thing? My datasource name is UserDs
----------------------------------------- 1718 [main] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{} 8249 [main] FATAL org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: OamDs javax.naming.NameNotFoundException: Unable to resolve 'UserDs'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'UserDs'. Resolved '']; remaining name 'UserDs' at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:195) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:338) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:252) at weblogic.jndi.internal.ServerNamingNode_921_WLStub.lookup(Unknown Source) at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:374) at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:362) at javax.naming.InitialContext.lookup(InitialContext.java:351) at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
In JBoss, you actually don't need to create your own jndi.properties, there is already one in the app server there. You just deploy your datasource with an xxx-ds.xml file, and in your hibernate or JPA config file pointing to that datasource.
You might want to create a new thread in the Weblogic forum for this issue. Unless someone else comes in this thread with Weblogic 9.2 experience.