Bonjour,

Je souhaite migrer un projet, qui utilisent Hibernate 4.0 avec le mapping XML, pour évoluer vers un mapping avec des annotations.
J’ai décidé un peu tard de passer aux annotations.
Je reprends un vieux projet, et je souhaite retrouver la même chose qu’avec les EJB 3.
C’est pourquoi je pense que ça vient de ma configuration.
J’obtiens toujours le même message d’ ‘erreur.
«2014-11-26T15:53:59.480+0100 ERROR user lacks privilege or object not found: FOO«

J’ai beau chercher, je ne trouve pas.
J’ai écrit une classe simple Foo.java et un code pour y accéder Teste Foo.java.
Pour la configuration je passe par le code, au lieu de XML.

Est-il possible de méllanger des classes avec des annotations et des configurations XML ?
Je souhaite évoluer progressivement.
Concernant les annotations faut-il utiliser celle de JPA ou d’hibernate ?

Merci d’avance pour votre aide

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
 
@Entity
public class Foo {
	protected int id;
	protected String name;
 
	public Foo() {
	}
 
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}
 
	public void setId(int id) {
		this.id = id;
	}
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
 
	@Override
	public String toString() {
		return "Foo [id=" + id + ", name=" + name + ", getId()=" + getId()
				+ ", getName()=" + getName() + ", getClass()=" + getClass()
				+ ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}
}
 
 
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
 
public class TestFoo {
	public static void main(String[] args) {
		AnnotationConfiguration configuration = new AnnotationConfiguration();
 
		configuration
				.setProperty("hibernate.dialect",
						"org.hibernate.dialect.HSQLDialect")
				.setProperty("hibernate.connection.driver_class",
						"org.hsqldb.jdbcDriver")
				.setProperty("hibernate.connection.url",
						"jdbc:hsqldb:file:local/foo.hsql")
				.setProperty("hibernate.connection.username", "sa")
				.setProperty("hibernate.connection.password", "");
 
		configuration.setProperty("hibernate.connection.pool_size", "4");
		configuration.setProperty("hibernate.connection.autocommit", "true");
		configuration.setProperty("hibernate.cache.provider_class",
				"org.hibernate.cache.NoCacheProvider");
		configuration.setProperty("hibernate.transaction.factory_class",
				"org.hibernate.transaction.JDBCTransactionFactory");
		configuration.setProperty("hibernate.current_session_context_class",
				"thread");
 
		new SchemaUpdate(configuration);
 
		configuration.addAnnotatedClass(Foo.class);
 
		SessionFactory sessionFactory = configuration.buildSessionFactory();
 
		Session session = sessionFactory.openSession();
 
		Transaction transaction = session.beginTransaction();
 
		Foo foo = new Foo();
		foo.setName("Une autre foo");
 
		session.persist(foo);
 
		transaction.commit();
 
		session.close();
	}
}