Bonjour,
j'utilise SPRING et Hibernate et j'ai ma classe User.java comme suit:
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
public class User {
	private Long id;
	private String login;
	private String password;
 
	public Long getId() {
		return id;
	}
 
	public void setId(Long id) {
		this.id = id;
	}
 
	public String getLogin() {
		return login;
	}
 
	public void setLogin(String login) {
		this.login = login;
	}
 
	public String getPassword() {
		return password;
	}
 
	public void setPassword(String password) {
		this.password = password;
	}
}
et mon fichier hibernate.cfg.xml :
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
<?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.hsqldb.jdbcDriver</property>
		<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
		<property name="connection.username">sa</property>
		<property name="connection.password"></property> 
        <!-- JDBC connection pool (use the built-in) -->
		<property name="connection.pool_size">2</property> 
 
        <!-- SQL dialect -->
		<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
		<!--
			Drop and re-create the database schema on start-up, also try with
			“update” to keep the previous values
		-->
		<property name="hbm2ddl.auto">create</property> 
 
        <!-- Echo all executed SQL to stdout -->
		<property name="show_sql">true</property>
		<mapping resource="xx/yy/User.hbm.xml" />
	</session-factory>
</hibernate-configuration>
enfin le fichier User.hbm.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?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="xx.yy.User" table="User">
		<id name="id" column="user_id">
			<generator class="native" />
		</id>
		<property name="login" column="login" />
		<property name="password" column="password" />
	</class>
</hibernate-mapping>
1- est il possible de générer une table de base de données à l'aide d'hibernate sans pour autant faire les classes qui font les CRUD ?
2- quelles sont les bonnes pratiques : l'utilisation des annotations ou le fichier de mapping.
s'il y en a d'autres méthodes ou bien des bons tuto qui peuvent m'aider je suis preneur.
merci