Bonjour à vous tous,

Je développe une application WEB JAVA EE, qui intégre SPRING IOC, SPRING DATA, HIBERNATE et JAX RS (Implémentation JERSEY).
Je vous présente mon POM.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<repositories>
		<repository>
			<id>maven2-repository.java.net</id>
			<name>Java.net Repository for Maven</name>
			<url>http://download.java.net/maven/2/</url>
			<layout>default</layout>
		</repository>
	</repositories>
 
	<!-- DEPENDENCIES -->
	<dependencies>
		<!-- JAVA EE -->
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
		</dependency>
 
		<!-- LOG4J -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
 
		<!-- HIBERNATE CORE -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>4.3.11.Final</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.3.11.Final</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate.common</groupId>
			<artifactId>hibernate-commons-annotations</artifactId>
			<version>4.0.4.Final</version>
		</dependency>
 
		<!-- SLF4J -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.13</version>
		</dependency>
 
		<!-- MYSQL CONNECTOR -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.9</version>
		</dependency>
 
		<!-- SPRING -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-jpa</artifactId>
			<version>1.7.1.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
		</dependency>
		<dependency>
			<groupId>com.zaxxer</groupId>
			<artifactId>HikariCP</artifactId>
			<version>2.2.5</version>
		</dependency>
 
		<!-- PROJECT LOMBOK -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.16.6</version>
			<scope>provided</scope>
		</dependency>
 
		<!-- JERSEY -->
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-bundle</artifactId>
			<version>1.18.1</version>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-json</artifactId>
			<version>1.8</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>1.7.7</version>
		</dependency>
 
		<!-- Jersey + Spring -->
		<dependency>
			<groupId>com.sun.jersey.contribs</groupId>
			<artifactId>jersey-spring</artifactId>
			<version>1.8</version>
			<exclusions>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-core</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-web</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-beans</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.springframework</groupId>
					<artifactId>spring-context</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
 
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-framework-bom</artifactId>
				<version>4.1.4.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
J'ai structuré mon application en des couches (DAO : Interface + Implémentation), (Service : Interface + Implémentation).

Ici mon Interface DAO:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
public interface IUserDAO extends IAbstractDAO<Long, User> {
 
	User find(String ssoId);
 
	User find(String login, String password);
}
Ici l'implémentation du DAO :
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
 
@Repository
public class UserDAOImpl extends AbstractDao<Long, User> implements IUserDAO {
 
	@Transactional
	@Override
	public User find(String ssoId) {
		return (User) createEntityCriteria().add(Restrictions.eq("ssoId", ssoId)).uniqueResult();
	}
 
	@Transactional
	@Override
	public User find(String ssoId, String password) {
		Criteria criteria = createEntityCriteria(); 
		criteria.add(Restrictions.eq("ssoId", ssoId));
		criteria.add(Restrictions.eq("password", password));
 
		return (User) criteria.uniqueResult();
	}
 
}
ici l'interface du Service :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
public interface IUserService extends IAbstractService<Long, User> {
 
	User find(String ssoId);
 
	User find(String login, String password);
}
ici son implémentation :
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
 
@Service("userService")
public class UserServiceImpl implements IUserService, IAbstractService<Long, User> {
 
	@Autowired
	private IUserDAO dao;
 
	@Override
	public User find(String ssoId) {
		return dao.find(ssoId);
	}
 
	@Override
	public User find(String login, String password) {
		return dao.find(login, password);
	}
 
}
Jusqu'à la je pense que tout est OK
Maintenant mon Service REST que j'ai développé de cette manière :
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
 
@Component
@Path(value = "/userAPI")
public class UserAPI {
 
	@Autowired
	IUserService service;
 
	@POST
	@Path("/authenticate")
	@Produces(MediaType.TEXT_PLAIN)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public User toAutenticate(@FormParam("ssoId") String ssoId, @FormParam("password") String password) {
		User user = service.find(ssoId, password);
		return user;
	}
 
	@GET
	@Path("/all")
	@Produces(MediaType.APPLICATION_JSON)
	public List<User> getAll(){
		List<User> list = service.getAll();
		for (User user : list) {
			System.out.println(user.getFirstName());
		}
		return list;
	}
 
}
Le problème c'est que le bug se génère une fois je fais appelle à la méthode qui interagit avec la Base de données. Donc je pense que mon problème est au niveau de HIBERNATE et non pas le REST
Bug :: org.hibernate.type.SerializationException: could not deserialize

Mes entités :
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
 
@Entity(name = IConstantTable.USER)
@NoArgsConstructor
public class User implements Serializable {
 
	private static final long serialVersionUID = -8805442486363117552L;
 
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Getter
	private long id;
 
	@Column(name = IConstantColumn.REGISTER_ID, length = 256, nullable = true, unique = true, updatable = true)
	@Getter
	@Setter
	private String registerId;
 
	@Column(name = IConstantColumn.SSOID, length = 256, nullable = true, unique = true, updatable = true)
	@Getter
	@Setter
	private String ssoId;
 
	@Column(name = IConstantColumn.PASSWORD, length = 256, nullable = true, unique = true, updatable = true)
	@Getter
	@Setter
	private String password;
 
	@Column(name = IConstantColumn.STATE, length = 10, nullable = true, unique = false, updatable = true)
	@Getter
	@Setter
	private String state = EState.ACTIVE.getName();
 
	@Column(name = IConstantColumn.FIRST_NAME, length = 100, nullable = false, unique = false, updatable = true)
	@Getter
	@Setter
	private String firstName;
 
	@Column(name = IConstantColumn.LAST_NAME, length = 100, nullable = false, unique = false, updatable = true)
	@Getter
	@Setter
	private String lastName;
 
	@Column(name = IConstantColumn.EMAIL, length = 100, nullable = false, unique = true, updatable = true)
	@Getter
	@Setter
	private String email;
 
	@Column(name = IConstantColumn.PHONE_NUMBER, length = 15, nullable = true, unique = true, updatable = true)
	@Getter
	@Setter
	private String phoneNumber;
 
	@Column(name = IConstantColumn.CITY, length = 100, nullable = true, unique = false, updatable = true)
	@Getter
	@Setter
	private String city;
 
	@Column(name = IConstantColumn.COUNTRY, length = 100, nullable = true, unique = false, updatable = true)
	@Getter
	@Setter
	private String country;
 
	@ManyToMany(fetch = FetchType.EAGER,cascade=CascadeType.ALL)
	@JoinTable(name = IConstantTable.USER_PROFILE, joinColumns = {
			@JoinColumn(name = IConstantColumn.USER_ID) }, inverseJoinColumns = {
					@JoinColumn(name = IConstantColumn.PROFILE_ID) })
	@Getter
	@Setter
	private List<Profile> roles;
 
	@LazyCollection(LazyCollectionOption.FALSE)
	@OneToMany(mappedBy = "user", targetEntity = Announcement.class, orphanRemoval = true,cascade = CascadeType.ALL)
	@Getter
	@Setter
	private List<Announcement> announcements;
 
}
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
 
@Entity(name = IConstantTable.ANNOUNCEMENT)
@JsonIgnoreProperties("user")
public class Announcement implements Serializable {
 
	private static final long serialVersionUID = 1599026440338597759L;
 
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Getter
	private long id;
 
	@Column(name = IConstantColumn.TITLE, length = 150, nullable = false, unique = false, updatable = true)
	@Getter
	@Setter
	private String title;
 
	@Column(name = IConstantColumn.DESCRIPTION, length = 500, nullable = false, unique = false, updatable = true)
	@Getter
	@Setter
	private String description;
 
	@Column(name = IConstantColumn.PUBLICATION_DATE, nullable = false, unique = false, updatable = false)
	@Getter
	private LocalDate publicationDate;
 
	@Column(name = IConstantColumn.PRICE, nullable = false, unique = false, updatable = true)
	@Getter
	@Setter
	private double price;
 
	@LazyCollection(LazyCollectionOption.FALSE)
	@ManyToOne(optional = false, targetEntity = User.class)
	@Cascade(CascadeType.ALL)
	@Getter
	@Setter
	private User user;
 
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "announcement", orphanRemoval = true, targetEntity = Product.class)
	@Cascade(CascadeType.ALL)
	@Getter
	@Setter
	List<Product> products;
 
	public Announcement() {
		this.publicationDate = LocalDate.now();
	}
}