File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes problem in pro EJB3 chapter 2 code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "problem in pro EJB3 chapter 2 code" Watch "problem in pro EJB3 chapter 2 code" New topic
Author

problem in pro EJB3 chapter 2 code

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Hi all,

I am trying to run the example in chapter 2 of the pro EJB3 JPA book. The only difference is I am using Jboss instead of Glassfish as in the persistence.xml code in the book.

When I ran the client, I got this exception

Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:695)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.entity.client.EmployeeTest.main(EmployeeTest.java:20)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:688)
... 4 more

I then inclued the hibernate dialect property in the persistence.xml file. My persistence.xml is as follows:



But I still get the same exception. Please help.


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Guys, any clues?
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

since you are using "RESOURCE_LOCAL" the application need the persistence.xml
so make sure the META-INF/ folder is available in your classpath.
(took me 1 hour to figure it out when i tried that example...)

second, since you are using it the local way, the <jta-data-source> is not necessary,
it's used to map to a datasource in the server.


SCJP 5, SCWCD 5, SCBCD 5
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Jonathan Elkharrat wrote:since you are using "RESOURCE_LOCAL" the application need the persistence.xml
so make sure the META-INF/ folder is available in your classpath.
(took me 1 hour to figure it out when i tried that example...)

second, since you are using it the local way, the <jta-data-source> is not necessary,
it's used to map to a datasource in the server.


When I removed the jta-data-source element and deployed the jar, the server complained of not having used the element
So I put back that element

Also, Secondly I added the META-INF folder in the path variable in Control Panel <- is this what you meant? Or i was supposed to add something to the jboss run time in eclipse?

But I still get the same error Hibernate Dialect must be explicitly set
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Jonathan,

I was using EntityManagerFactory emf = Persistence.createEntityManagerFactory("EmployeeService"); in the client code, where as my persistence.xml had <persistence-unit name="EntityService"

I changed the client code to use EntityService nad tired running the client again.

This time I got the exception - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap at the line

EntityManagerFactory emf = Persistence.createEntityManagerFactory("EntityService");

Any clues? Am i missing any jars in to server runtime >
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Any clues? Am i missing any jars in to server runtime


Please help!
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

you don't need the server if you are using "RESOURCE_LOCAL".
J2SE take care of everything, you just need to provide it the
persistence.xml in the classpath.
but you need a database running of course.
so what exactly are you trying to do?
in Pro EJB3 in listing 2-10 they are doing it from J2SE...
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
I am also trying to run it in j2se. For the HSQL database to be up and running, I start the JBoss Server.
Till now I had deployed the jar on the server, and then running the client to the application. But get the error as in my post above.

Since this is a j2se app, I tried removing the deployed jar on the server, started the server, then the HSQL database, and then simply ran the client. Again I got the same error.

Guys, I am confused! How do I run this J2se ejb app? The J2EE app is executed by jarring up and deploying it on the server.

But how do i run the j2se apps as in the chapter 2?
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

i'm not sure you need to know how to do that for the exam,
but here's my persistence.xml for example.
(don't forget to check the META-INF is accesible via your classpath)

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
The xml file is for MYSql. I am using the HSQL database that comes with JBoss.

Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

i know. but you need to configure yours, including "hibernate.connection.url"
so your application know where to connect (when connecting from server it's handled automatically)
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
I tried to find the values for the follwoing properties in JBoss documentation, but did not found them-

"hibernate.connection.driver_class"
"hibernate.connection.username"
"hibernate.connection.password"
"hibernate.connection.url"


Can any one help me? If the values for these are available I can still use Jboss, else the last option left with me is using glass fish - toplink/derby/mysql!

It would be really great if I have two persistence.xml files, one for Jboss and other for glassfish!
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Guys, finally I was able to run the application!

I had the GlassFist v2 ur2 with MySql installed first. Then I started the mysql database server from the start menu shortcut. The database server runs on 3036 port!

I juggled around with mysql as seen in this thread!

1. added mysql-connector-java-5.1.6-bin.jar to application class path.
2. added persistence.xml to application class path.
3. added commons-collections.jar to application class path.
4. Modified persistence.xml to use the proper port number and database name in the connection url,
used proper user name and password.

The persistence.xml is:



I changed the password of the root user as:

C:\Sun\AppServer\mysql\bin>mysqladmin -u root password root

and then used it in the persistence.xml. Some of the informative links are:

http://anaturb.net/MySQL/mysql_commands.htm
http://www.cyberciti.biz/faq/mysql-change-root-password/

You can check the data in the mysql database as:

C:\Sun\AppServer\mysql\bin>mysql -u root -p
Enter password: **** <- enter root here

mysql>SELECT CURRENT_USER();
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> use mysql;
mysql>show tables; (the employee table can be seen)
mysql>select * from employee; (see the data)


The exam does not expect you to know all this. But what is the point if one can not run a sample ejb application, so I thought of just having these problems solved and see the CRUD operation in action.

Hth other folks here trying to juggle around and run some code
 
Don't get me started about those stupid light bulbs.
 
subject: problem in pro EJB3 chapter 2 code