Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/appconfig-data.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
- @Entity
- @Table(name = "users")
- public class UserEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- @Column(name = "username")
- protected String username;
- @Column(name = "password")
- protected String password;
- @Transient
- private String confirmPassword;
- @ManyToMany
- @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
- inverseJoinColumns = @JoinColumn(name = "role_id"))
- private Set<Role> roles;
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getConfirmPassword() {
- return confirmPassword;
- }
- public void setConfirmPassword(String confirmPassword) {
- this.confirmPassword = confirmPassword;
- }
- public Set<Role> getRoles() {
- return roles;
- }
- public void setRoles(Set<Role> roles) {
- this.roles = roles;
- }
- @Entity
- @Table(name = "roles")
- public class RoleEntity{
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- @Column(name = "name")
- private String name;
- @ManyToMany(mappedBy = "roles")
- private Set<User> users;
- public RoleEntity() {
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Set<User> getUsers() {
- return users;
- }
- public void setUsers(Set<User> users) {
- this.users = users;
- }
- @Override
- public String toString() {
- return "Role{" +
- "id=" + id +
- ", name='" + name + ''' +
- ", users=" + users +
- '}';
- }
- public class User extends UserEntity implements Comparable {
- private boolean isOnline;
- private String sex;
- private int age;
- private String comment;
- private String email;
- private String friendsLogins;
- private Session session;
- public User(String login, String password) {
- this.sex = null;
- this.comment = null;
- this.email = null;
- this.friendsLogins = "";
- }
- public User(User user) {
- this.sex = user.getSex();
- this.comment = user.getComment();
- this.email = user.getComment();
- this.friendsLogins = "";
- }
- public User(String login, String password, boolean isOnline, String sex, int age, String comment, String email) {
- this.sex = sex;
- this.age = age;
- this.comment = comment;
- this.email = email;
- this.friendsLogins = "";
- }
- public Session getSession() {
- return session;
- }
- public void setSession(Session session) {
- this.session = session;
- }
- public boolean isOnline() {
- return isOnline;
- }
- public void setOnline(boolean online) {
- isOnline = online;
- }
- public String getSex() {
- return sex;
- }
- public void setSex(String sex) {
- this.sex = sex;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public String getComment() {
- return comment;
- }
- public void setComment(String comment) {
- this.comment = comment;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getFriendsLogins() {
- return friendsLogins;
- }
- public void setFriendsLogins(String friendsLogins) {
- this.friendsLogins = friendsLogins;
- }
- public boolean equals(Object obj) {
- User user = (User) obj;
- if (user.getPassword().equals(this.password) && user.getUsername().equals(this.username)) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public int compareTo(Object o) {
- User user = (User) o;
- if (user.getPassword().equals(this.password) && user.getUsername().equals(this.username)) {
- return 0;
- } else if (user.getAge() > this.getAge()) {
- return -1;
- } else {
- return 1;
- }
- }
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${jdbc.driverClassName}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSource"/>
- <property name="packagesToScan" value="com.chat.my.model"/>
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
- </property>
- <property name="jpaProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- </bean>
- <bean id="transactionManager"
- class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory"/>
- </bean>
- <tx:annotation-driven/>
- <jpa:repositories base-package="com.chat.my.dao"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement