I'm new to JPA i 'm using eclipse Galileo and i want to run one JPA program
1) i had created one entity for table
2) i had created one test class to test the entity
3) i added Jpa.jar file in bulid path
But when i build the JPAproject it is showing one error Entity "TableName" has no id or embeded id
please giude me how to over come this i'm not using any hibernate and spring frame work just i'm running in stand alone application
In your class you have not mentioned the primary key by marking it wihth @Id annotation.
The other one about @EmbeddedId means that you write a different class as the primary key and then you have a reference of it in your class and mark it with @EmbeddedId annotation.
I think if you can share your code we can point at exact location of error.
Hope this helps.
Thanks,
Prabhat
SCJP 1.5, SCWCD 1.5, SCBCD 1.5
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
posted
0
Test class
Table name= ActivityMaster
In my table i'm not using any primary key it is just a table to test the JPA program
That's a nice, long, piece of code. What would you like to know about it?
Might I suggest starting small and working up. Get something simple going.
I'd suggest using a primary key if you want to save your data. They're not optional in relational databases that use object relational mapping tools like Hibernate.
They're not optional in relational databases that use object relational mapping tools like Hibernate.
is it not possible to run the JPAGetResultList program with out using hibernate
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35440
9
posted
0
is it not possible to run the JPAGetResultList program with out using hibernate
Well, you must use *some* JPA implementation. If you don't want to use Hibernate, then OpenJPA and EclipseLink are other options. But, thanks to JPA being a standard, they should all work the same.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Have you tried to run it? Regardless of what JPA implementation you use, be it TopLink or Hibernate or EJB, you'll need a primary key and an id field in your JPA entity.
A good way to learn is to run programs and look at the result. Does it run? Does it work? Does it throw a runtime exception? Does it throw a runtime error?
Run the program! Then, if you run into a problem, explain the problem and we'll try and help you understand what is happening.
If you're not sure of the purpose of a primary key in a database table, you might want to start learning a bit more about databases and tables before jumping into JPA and Hibernate programming. The purpose of a primary key or id field in a JPA entity is really the same as the purpose in a database table.
Prabhat Jha
Ranch Hand
Joined: Aug 13, 2007
Posts: 58
posted
0
Since you dont have primary key in your table then you just cannot do it.
can any body tell how to run openJPA for stand alone application
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
posted
0
when i run the program it giving me
Error:javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
Prabhat Jha
Ranch Hand
Joined: Aug 13, 2007
Posts: 58
posted
0
In your mapping i see this
and in your code i see this
Change it to
It should work.
santhosh.R gowda
Ranch Hand
Joined: Apr 06, 2009
Posts: 296
posted
0
I had changed to JPADemo
but still im getting the runtime error when i execute the first statement
Do you have necessary jar files in your class file ?
Also where is your persistence.xml located it should be in META-INF.
I think it is taking quite some time to fix your problem so i will say share your project structure and all the details like which all jars you have placed and where?