Bonjour,
j'ai un petit souci avec la creation de mes tables avec hibernate:
il n y a pas de cascade lorsque je vérifie le script sql de ma base de données, pourtant j'ai bien spécifié l'attribut cascade = CascadeType.ALL
voila un exemple d'une entité parmi d'autre et comment je procède :
j'utilise mysql, voila le 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 @Entity @Table(name = "item") public class Item implements java.io.Serializable { /** * */ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "IDitem", unique = true, nullable = false) private int iditem; @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "IDDIVISION", nullable = false) private Division division; @Column(name = "SIGLE", length = 254) private String sigleItem; @Column(name = "DESCRIPTION", length = 254) private String description; ...
et le application-context.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 <?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 name="session1"> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dac_bd4</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"></property> <property name="current_session_context_class">thread</property> <property name="hibernate.show_sql">true</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!--Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="hibernate.cache.use_second_level_cache">false </property> <property name="hibernate.cache.use_query_cache">true</property> <property name="hibernate.cache.use_structured_cache">true</property> <property name="hibernate.cache.use_minimal_puts">true</property> <property name="hibernate.hbm2ddl.auto">create</property> </session-factory> </hibernate-configuration>
.
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 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/dac_bd4</value> </property> <property name="username"> <value>root</value> </property> </bean> <bean id="SessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>Dac.Entity.Division</value> <value>Dac.Entity.Historique</value> <value>Dac.Entity.Item</value> <value>Dac.Entity.Role</value> <value>Dac.Entity.Utilisateur</value> <value>Dac.Entity.Habilitation</value> <value>Dac.Entity.Statu</value> <value>Dac.Entity.Audit</value> <value>Dac.Entity.Question</value> <value>Dac.Entity.Questionnaire</value> <value>Dac.Entity.Referencereglementaire</value> <value>Dac.Entity.Reponse</value> <value>Dac.Entity.Theme</value> <value>Dac.Entity.OrganismeAudite</value> <value>Dac.Entity.RefQuest</value> <value>Dac.Entity.Ecarts</value> <value>Dac.Entity.NiveauEcart</value> <value>Dac.Entity.Personnerencontree</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="SessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <context:annotation-config /> <context:component-scan base-package="Dac" /> </beans>
Merci pour votre aide!
Partager