Jacek Laskowski wrote:
On Sat, Jan 24, 2009 at 2:02 AM, Martin Uhlir <[email protected]> wrote:
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR:
relation "country" does not exist {prepstmnt 16963612 INSERT INTO Country
(id, name) VALUES (?, ?) [params=(long) 5, (String) aaa]} [code=0,
state=42P01]
...
What does this '.....relation "country" does not exist".....' mean? I'm just
using this simple entity bean which I try to persist in a stateless session
bean.
@Entity
public class Country {
private Long id;
private String name;
public void setId(Long id) {
this.id = id;
}
@Id
public Long getId() {
return id;
}
How do you work with the entity? Why was the id 5 in the exception if
it had never worked before? Did PostgreSQL assign 5 from the very
begining? You didn't set the id yourself, did you? Show the relevant
session ejb snippet where the entity is used.
There is nothing interesting about the ejb snippet. I was just "greedy"
to see it running (the creation of tables by OpenJPA in db when getting
EntityManager for the first time) so I made it as simple as possible :-)
Country c = new Country();
c.setId(5L);
em.persist(c);
I also wonder if no @GeneratedValue with @Id causes the exception.
9.1.9 GeneratedValue Annotation in the EJB 3.0 spec reads (AUTO is the
default value):
Thanks for noticing me about this fact, but there was really no
exception in the log when I didn't use the GenerationValue annotation
together with Id.
The AUTO value indicates that the persistence provider should pick an
appropriate strategy for the particular database. The AUTO generation
strategy may expect a database resource to exist, or it may attempt to
create one. A vendor may provide documentation on how to create such
resources in the event that it does not support schema generation or
cannot create the schema resource at runtime.
That's why the exception contained reference to "relation country",
but it still doesn't sound good.
Btw. in the meantime I installed MySQL instead of PostgreSQL and used
its connection and suddenly everything worked just fine..
Still I dont know where the problem with PostgreSQL was, I used the
"superuser" who has all rights (grants) to do in db..
BTW, you don't have to use the wrapper classes, e.g. Long for entity
fields - primitive types work fine, e.g. long.
Jacek