I'm having problems putting eclipse+hibernate+postgre working.
These are my classes and mapping file:
Code:
public class Leitor {
private String id;
private int posX;
private int posY;
private int posZ;
private String Nome;
public String getNome() {
return Nome;
}
public String getId() {
return id;
}
public int getPosX() {
return posX;
}
public int getPosY() {
return posY;
}
public int getPosZ() {
return posZ;
}
public void setId(String string) {
id = string;
}
public void setNome(String string) {
Nome = string;
}
public void setPosX(int i) {
posX = i;
}
public void setPosY(int i) {
posY = i;
}
public void setPosZ(int i) {
posZ = i;
}
}
Code:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Teste {
public static void main(String[] args) {
Session session = null;
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("Inserting Record");
Leitor leitor = new Leitor();
leitor.setId("1");
leitor.setPosX(90);
leitor.setPosY(50);
leitor.setPosZ(130);
leitor.setNome("Leitor 1");
session.save(leitor);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
session.flush();
session.close();
}
}
}
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="acessoBanco.Leitor" table=""LEITOR"" schema=""SITRACK"">
<id name="id" length="15" type="string">
<column name=""ID"" />
<generator class="assigned"/>
</id>
<property name="posX" type="integer">
<column name=""POSICAO_X"" />
</property>
<property name="posY" type="integer">
<column name=""POSICAO_Y""/>
</property>
<property name="posZ" type="integer">
<column name=""POSICAO_Z""/>
</property>
<property name="nome" length="50" type="string">
<column name=""NOME""/>
</property>
</class>
</hibernate-mapping>
It doesn't show any errors, but doesn't insert the values either.
Looking in the postgre log file i noticed this:
2009-09-12 13:33:34 BRT LOG: loaded library "$libdir/plugins/plugin_debugger.dll"
2009-09-12 13:33:35 BRT ERROR: relation "LEITOR" already exists
2009-09-12 13:33:35 BRT STATEMENT: create table "SITRACK"."LEITOR" ("ID" varchar(255) not null, "POSICAO_X" int4, "POSICAO_Y" int4, "POSICAO_Z" int4, "NOME" varchar(255), primary key ("ID"))
2009-09-12 13:33:35 BRT LOG: unexpected EOF on client connection
It's trying to create the table instead of inserting the values.
Does anybody knows whats happening?
Thank you.