joib wrote:
Well, obviously the .hbm.xml file that you're trying to map is not the same that you showed above, as the Exception tells that it still tries to use the identity generator.
Using seqhilo is as easy as sequence, once you get sequence to work you can just change "sequence" in the hbm.xml file to "seqhilo" and everything should work.
I've created a new project with a class
Person as follow:
Code:
public class Person
{
protected int id;
protected String name;
public Person() {}
public Person(String name) { this.name = name; }
public int getId() { return id; }
public String getName() { return name; }
public void setId(int i) { id = i; }
public void setName(String string) { name = string; }
}
The class Main is as follow defined:
Code:
// imports ...
public class Main
{
public static void main(String[] args)
throws MappingException, HibernateException
{
Configuration cfg = new Configuration();
cfg.addClass(Person.class); // error line (line 19)
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
Transaction tx = null;
Person p = new Person("John Smith");
p.setName("John Smith");
try
{
tx = session.beginTransaction();
session.save(p);
tx.commit();
}
catch (HibernateException he)
{
if (tx != null)
tx.rollback();
throw he;
}
finally
{
session.close();
}
}
}
The mapping file
Person.hbm.xml is as follw:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Person" table="t_personen">
<id name="id" type="integer" column="id">
<generator class="sequence">
<param>id_sequence</param>
</generator>
</id>
<property name="name" column="name" not-null="true" />
</class>
</hibernate-mapping>
And lastly the
hibernate.properties file:
Code:
hibernate.connection.username=student
hibernate.connection.password=geheim
hibernate.connection.url=jdbc:postgresql://localhost/personen
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect
I've created the database personen and with the follwong script the table t_personen:
Code:
CREATE SEQUENCE id_sequence START 1 INCREMENT 1;
CREATE TABLE t_personen
(
id INTEGER PRIMARY KEY,
name VARCHAR(32) NOT NULL
)
If I try to execute my project, I have the folloving message:
[code]...
06.04.2004 16:13:45 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
06.04.2004 16:13:45 net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: Person.hbm.xml
06.04.2004 16:13:45 net.sf.hibernate.util.XMLHelper$ErrorLogger error
SCHWERWIEGEND: Error parsing XML: XML InputStream(11) Attributwert f