I know that this should be the first post, but somehow I did not have the time or desire sklecać everything (all configurations) from the beginning. Well I finally did it and I did the first, a simple application that writes to the database one tuple.
My POJO is very simple:
public class Category {
Integer id;
String name;
public Integer getId () {return id
;
} public void setId (Integer id) {
this . id = id;}
public String getName () {return name
;
} public void setName (String name) {this.name = name
;
}}
to this as easy mapping:
\u0026lt;hibernate-mapping package="main">
\u0026lt;class name="Category">
ID> name="id" value="null" column="category_id">
\u0026lt;generator class="sequence">
\u0026lt;/ generator> \u0026lt; , / id> \u0026lt;/ class> \u0026lt;/ hibernate-mapping> \u0026lt;paramname="sequence"> category_seq
\u0026lt;property name="name">
\u0026lt;/ property>
configuration file looks like follows:
\u0026lt;? xml version = "1.0" encoding = "UTF-8"?>
\u0026lt;DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testy
</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver
</property>
<property name="hibernate.connection.username">test</property>
<property name="hibernate.connection.password">test</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="hibernate.show_sql">false</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="main\Category.hbm.xml" />
</session-factory>
</hibernate-configuration>
is contained in the configuration entry on the automatic creation of database schema-defined mapping files:
\u0026lt;property name="hbm2ddl.auto"> create \u0026lt;/ property>
main class of the project is as follows:
public class
Main {public static void main (String [] args) {Session session
= null;
SessionFactory SessionFactory = new Configuration (). configure (). buildSessionFactory ();
sessionFactory.openSession session = ();
Category cat = new Category ();
cat.setName ("name");
session.beginTransaction ();
session.save (cat);
session.flush ();
session.getTransaction (). Commit ();
session.close ();
System.out.println ("end");
}}
greatest difficulty can make selecting the correct dependencies. A working configuration is as follows:
- antlr-2.7.6.jar
- backport-util-concurrent-3.1.jar
- postgresql-8.1-407.jdbc3.jar
- ehcache-1.5.0.jar
- log4j-
1.2.14.jar - commons-collections-3.2.jar
- dom4j-1.6.1.jar
- commons-logging-1.1.1.jar
- hibernate-3.2.5.ga.jar
- jta-1.0 .1 B.jar
- xml-apis-1.3.03.jar
- cglib-nodep-2.1_3.jar
0 comments:
Post a Comment