Fórum Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity #8404
07/08/2009
0
Estou com o eclipse galileo, utilizando JBoss Tool.
aqui está meu persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="conexao" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/consultas.xml</mapping-file>
<class>br.com.entidades.People</class>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="1234" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
<persistence-unit name="xxx" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/consultas.xml</mapping-file>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="1234" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/SISCONTV" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
</persistence>
aqui está minha classe People
package br.com.entidades;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity(name="People")
public class People implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(nullable= false , name="id")
private Integer id;
@Column(name="name")
private String name;
@Column(name="age")
private Integer age;
/**
*
*/
public People() {
}
public People(Integer id){
this.id = id;
}
/**
* @param id
* @param name
* @param age
*/
public People(Integer id, String name, Integer age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public Integer getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(Integer age) {
this.age = age;
}
/**
* @return the serialversionuid
*/
public static long getSerialversionuid() {
return serialVersionUID;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
People other = (People) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
e aqui está minha appClass
package br.com;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.entidades.People;
public class TheAppClass {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("conexao");
EntityManager em = emf.createEntityManager();
People p = em.find(People.class, 1);
System.out.println("Nome da pessoa é: " + p.getName());
em.close();
emf.close();
}
}
... Dae, da esse erro:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select people0_.id as id0_0_, people0_.age as age0_0_, people0_.name as name0_0_ from People people0_ where people0_.id=?
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not load an entity: [br.com.entidades.People#1]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:202)
at br.com.TheAppClass.main(TheAppClass.java:19)
Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [br.com.entidades.People#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1895)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:182)
... 1 more
Caused by: org.postgresql.util.PSQLException: ERRO: relação "people" não existe
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1547)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1315)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:190)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
... 13 more
...
e aqui como está no banco.
Euclides Filizola
Curtir tópico
+ 0Posts
07/08/2009
Dyego Carmo
Logo abaixo
@Entity(name="People")
coloque
@Entity(name="People")
@Table(name="People")
e teste denovo.
Gostei + 0
07/08/2009
Euclides Filizola
agora está aparecendo esse erro:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select people0_.id as id0_0_, people0_.age as age0_0_, people0_.name as name0_0_ from People people0_ where people0_.id=?
Exception in thread "main" java.lang.NullPointerException
at br.com.TheAppClass.main(TheAppClass.java:23)
Gostei + 0
07/08/2009
Dyego Carmo
Preciso do Stack Trace completo.
Gostei + 0
07/08/2009
Euclides Filizola
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select people0_.id as id0_0_, people0_.age as age0_0_, people0_.name as name0_0_ from People people0_ where people0_.id=?
Exception in thread "main" java.lang.NullPointerException
at br.com.TheAppClass.main(TheAppClass.java:23)
dae quando eu clico em br.com.TheAppClass.main(TheAppClass.java:23),
ele mostra a linha :
System.out.println("Nome da pessoa é: " + p.getName());
É como se não tivesse o Usuario número 1, não é ?
mas aqui está meu select:
Gostei + 0
07/08/2009
Dyego Carmo
Provavelmente nao existe este usuario cadastrado.
Gostei + 0
07/08/2009
Euclides Filizola
o erro que da no console é esse:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select people0_.id as id0_0_, people0_.age as age0_0_, people0_.name as name0_0_ from People people0_ where people0_.id=?
Exception in thread "main" java.lang.NullPointerException
at br.com.TheAppClass.main(TheAppClass.java:23)
.. Dae, é como se não tivesse o Usuario número 1.
mas ta aqui minha img.
Gostei + 0
07/08/2009
Dyego Carmo
Gostei + 0
07/08/2009
Euclides Filizola
Gostei + 0
07/08/2009
Dyego Carmo
Gostei + 0
07/08/2009
Euclides Filizola
Dae eu criei novamente o usuário ID=1,
Pronto, dae eu executei novamente a appClass
Porém, continua o mesmo erro:
Gostei + 0
07/08/2009
Dyego Carmo
Gostei + 0
07/08/2009
Euclides Filizola
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select people0_.id as id0_0_, people0_.age as age0_0_, people0_.name as name0_0_ from People people0_ where people0_.id=?
Nome da pessoa é: null
...
Gostei + 0
07/08/2009
Dyego Carmo
Gostei + 0
07/08/2009
Euclides Filizola
deixa eu te mostrar como está tudo atualmente aqui:
Classe People:
package br.com.entidades;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity(name="People")
@Table(name="People")
public class People implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@Column(name="id")
private Integer id;
@Column(name="name")
private String name;
@Column(name="age")
private Integer age;
/**
*
*/
public People() {
}
public People(Integer id){
this.id = id;
}
/**
* @param id
* @param name
* @param age
*/
public People(Integer id, String name, Integer age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public Integer getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(Integer age) {
this.age = age;
}
/**
* @return the serialversionuid
*/
public static long getSerialversionuid() {
return serialVersionUID;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
People other = (People) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
Class TheApp
package br.com;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.entidades.People;
public class TheAppClass {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("conexao");
EntityManager em = emf.createEntityManager();
People p = em.find(People.class,1);
System.out.println("Nome da pessoa é: " + p);
em.close();
emf.close();
}
}
meu persistence:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="conexao" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/consultas.xml</mapping-file>
<class>br.com.entidades.People</class>
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="1234" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
</properties>
</persistence-unit>
</persistence>
e aqui como está meu banco:
Gostei + 0
07/08/2009
Dyego Carmo
Pegue esse select que o hibernate tah dando e coloque o id = 1 e veja se retorna...
que estranho...
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)