I got this error.Some solutions said add javax.transaction to pom.xml.I did but not working.And some solutions said javaee.jar and javax.persistence.jar to my classpath.But not working.So how to i fix it?
User model
@Entity
@Table(name="users")
public class Users implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Integer id;
@Column(name="name")
private String name;
@Column(name="surname")
private String surname;
@Column(name="username")
private String username;
@Column(name="password")
private String password;
@Column(name="is_super_user")
private Boolean isSuperUser;
@Column(name="email")
private String email;
@Column(name="created_at")
private Date created_at;
@Column(name="updated_at")
private Date updated_at;
@PrePersist
protected void onCreate() {
created_at = new Date();
}
@PreUpdate
protected void onUpdate() {
updated_at = new Date();
}//and getter&setter
UserDao
@Repository
public class UsersDao {
@PersistenceContext
private EntityManager entityManager;
public void save(Users users){
entityManager.persist(users);
}
}
UserDto like model without this constructor
public UsersDto(){
}
public UsersDto(Users users){
this.id = users.getId();
this.name = users.getName();
this.surname = users.getSurname();
this.email = users.getEmail();
this.isSuperUser = users.getSuperUser();
this.username = users.getUsername();
this.password = users.getPassword();
}
UserResources
@Component
@Path("/users")
public class UsersResources {
@Autowired
UsersService usersService;
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response saveCity(UsersDto usersDto){
Users users;
try{
users = usersService.saveUsers(usersDto);
}catch (Exception e){
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return Response.ok(users).build();
}
}
UserServices
@Service
public class UsersService {
@Autowired
private UsersDao usersDao;
@Transactional
public Users saveUsers(UsersDto usersDto){
Users users = new Users();
users.setName(usersDto.getName());
users.setEmail(usersDto.getEmail());
users.setSuperUser(usersDto.getSuperUser());
users.setSurname(usersDto.getSurname());
users.setPassword(usersDto.getPassword());
usersDao.save(users);
return users;
}
}
Error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/SystemException
at
... 27 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/transaction/SystemException
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:375) ~[na:na]
at org.jboss.logging.Logger$1.run(Logger.java:2554) ~[jboss-logging-3.3.2.Final.jar:3.3.2.Final]
My pom.xml has spring boot starter (web security jersey jpa mysql) and javax.transaction
So how to i fix?