hibernate + adnotacje

0

witam, zaczynam z hibernate i próbuje zrobić testowe połączenie, ale wywala mi błędy których nie rozumiem. Wklejam kody klas + hibernate.cfg.xml, może ktoś pomoże..

package test;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name = "testbaza")
public class testbaza {
		
	private int id;
	private String name;
	
	public testbaza (int id, String name){
		this.id = id;
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	@Basic(optional = false)
	@Column(name = "name", unique = false, nullable = false)
	public String getName() {
		return name;
	}
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public void setName(String name) {
		this.name = name;
	}
}
package test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class addtest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SessionFactory factory = new Configuration().configure().buildSessionFactory();
		Session session = factory.openSession();
		session.beginTransaction();
		
		testbaza baza = new testbaza(1, "test");
		session.save(baza);
		session.getTransaction().commit();
		session.close();
		// TODO Auto-generated method stub

	}

}


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<session-factory>

		<!-- Database connection settings -->
		<property name="connection.driver_class">org.postgresql.Driver</property>
		<property name="connection.url">jdbc:postgresql://localhost:5432/testbaza</property>
		<property name="connection.username">postgres</property>
		<property name="connection.password">postgres</property>

		<!-- JDBC connection pool (use the built-in) -->
		<property name="connection.pool_size">0</property>

		<!-- SQL dialect -->
		<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

		<!-- Echo all executed SQL to stdout -->
		<property name="show_sql">false</property>

		<mapping class="test.testbaza" />
		
	</session-factory>

</hibernate-configuration>

błedy:

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
	at test.addtest.main(addtest.java:13)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	... 1 more
0

Jak sciagasz dystrybucje hibernate to jest tam katalog lib czy podobny gdzie jest pelno jarow. Jednym z nich jest jdom czy jakis podobny do pasrowania xml - dolacz go do classpath projektu. Dostaniesz pewnie inne bledy, bo inne jary tez musza byc dolaczone - najlatwiej poki co wrzucic do classpath wszystkie (jednak nie wszystkie sa zawsze uzywane, ja wole jary dobierac tylke to ktore sa faktycznie potrzebne).

0
pikseloza napisał(a)

Jak sciagasz dystrybucje hibernate to jest tam katalog lib czy podobny gdzie jest pelno jarow. Jednym z nich jest jdom czy jakis podobny do pasrowania xml - dolacz go do classpath projektu. Dostaniesz pewnie inne bledy, bo inne jary tez musza byc dolaczone - najlatwiej poki co wrzucic do classpath wszystkie (jednak nie wszystkie sa zawsze uzywane, ja wole jary dobierac tylke to ktore sa faktycznie potrzebne).

przy tworzeniu SessionFactory trzeba było zamiast Configuration użyć AnnotationConfuguration

SessionFactory factory = new Configuration().configure().buildSessionFactory();

poza tym wrzuciłem do jre do ext wcześniej biblioteki od hibernate, łącznie z tą brakującą jdom

1 użytkowników online, w tym zalogowanych: 0, gości: 1