2016-09-13 23 views
2

私は2つのドメインを持っています - ユーザーとカタログ... 1人のユーザーが多数のカタログを持つことができます。 は、これは私のUser.javaファイルですcom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:不明な列 '....'

package com.egs.account.model; 


import org.apache.commons.lang.builder.EqualsBuilder; 

import javax.persistence.*; 
import java.util.Date; 
import java.util.Set; 

@Entity 
@Table(name = "user") 
public class User { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
    private String username; 
    private String password; 

    @Transient 
    private String passwordConfirm; 
    private String firstName; 
    private String lastName; 
    private Date dateRegistered; 
    private Long skypeID; 

    @ManyToMany 
    @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id")) 
    private Set<Role> roles; 

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) 
    private Set<Catalog> catalogs; 

    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 getPasswordConfirm() { 
     return passwordConfirm; 
    } 

    public void setPasswordConfirm(String passwordConfirm) { 
     this.passwordConfirm = passwordConfirm; 
    } 

    public String getFirstName() { return firstName; } 

    public void setFirstName(String firstName) { this.firstName = firstName; } 

    public Date getDateRegistered() { return dateRegistered; } 

    public void setDateRegistered(Date dateRegistered) { this.dateRegistered = dateRegistered; } 

    public Long getSkypeID() { return skypeID; } 

    public void setSkypeID(Long skypeID) { this.skypeID = skypeID; } 

    public String getLastName() { return lastName; } 

    public void setLastName(String lastName) { this.lastName = lastName; } 

    public Set<Role> getRoles() { 
     return roles; 
    } 

    public void setRoles(Set<Role> roles) { 
     this.roles = roles; 
    } 

    public Set<Catalog> getCatalogs() { return catalogs; } 

    public void setCatalogs(Set<Catalog> catalogs) { this.catalogs = catalogs; } 

    @Override 
    public int hashCode() { 
     final int prime = 31; 
     int result = 1; 
     result = prime * result + ((id == null) ? 0 : id.hashCode()); 
     result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); 
     return result; 
    } 

    @Override 
    public boolean equals(final Object obj) { 
     if (!(obj instanceof User)) { 
      return false; 
     } 
     if (obj == this) { 
      return true; 
     } 
     final User other = (User) obj; 
     final EqualsBuilder builder = new EqualsBuilder(); 
     builder.append(this.firstName, other.firstName); 
     builder.append(this.lastName, other.lastName); 
     builder.append(this.username, other.username); 
     builder.append(this.skypeID, other.skypeID); 
     return builder.isEquals(); 
    } 

    @Override 
    public String toString() { 
     return "User [id=" + id + ", name=" + firstName + ", lastName=" 
       + lastName + ", username=" + username + "]"; 
    } 
} 

この1つは私のCatalog.javaファイル

package com.egs.account.model; 

import javax.persistence.*; 
import java.util.Date; 

@Entity 
@Table(name = "catalog") 
public class Catalog { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
    private String link; 
    private String comment; 
    private Date insertDate; 

    @ManyToOne(optional = false) 
    @JoinColumn(name = "USER_ID") 
    private User user; 

    @Lob @Basic(fetch = FetchType.LAZY) 
    @Column(name="content", nullable=false) 
    private byte[] content; 

    public Long getId() { 
     return id; 
    } 

    public void setId(Long id) { 
     this.id = id; 
    } 

    public String getLink() { return link; } 

    public void setLink(String link) { this.link = link; } 

    public String getComment() { return comment; } 

    public void setComment(String comment) { this.comment = comment; } 

    public Date getInsertDate() { return insertDate; } 

    public void setInsertDate(Date insertDate) { this.insertDate = insertDate; } 

    public User getUser() { return user;} 

    public void setUser(User user) { this.user = user; } 

    public byte[] getContent() { return content; } 

    public void setContent(byte[] content) { this.content = content; } 
} 

であるこの私が私のリポジトリ、サービス・クラスで を使用するものを拡張し、そこから私のabstractDaoクラスがあります。ここで私はそのエラーここ

import org.hibernate.Criteria; 
    import org.hibernate.Session; 
    import org.hibernate.SessionFactory; 
    import org.springframework.beans.factory.annotation.Autowired; 
    import org.springframework.transaction.annotation.Transactional; 

    import java.io.Serializable; 
    import java.lang.reflect.ParameterizedType; 

    @Transactional 
    public abstract class AbstractDao<PK extends Serializable, T> { 

     private final Class<T> persistentClass; 

     @SuppressWarnings("unchecked") 
     public AbstractDao(){ 
      this.persistentClass =(Class<T>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1]; 
     } 

     @Autowired 
     private SessionFactory sessionFactory; 

     protected Session getSession(){ 
      return sessionFactory.getCurrentSession(); 
     } 

     @SuppressWarnings("unchecked") 
     public T getByKey(PK key) { 
      return (T) getSession().get(persistentClass, key); 
     } 

     public void persist(T entity) { 
      getSession().persist(entity); 
     } 

     public void delete(T entity) { 
      getSession().delete(entity); 
     } 

     protected Criteria createEntityCriteria(){ 
      return getSession().createCriteria(persistentClass); 
     } 


    } 

私のHibernate設定

package com.egs.account.config; 

import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.PropertySource; 
import org.springframework.core.env.Environment; 
import org.springframework.jdbc.datasource.DriverManagerDataSource; 
import org.springframework.orm.hibernate4.HibernateTransactionManager; 
import org.springframework.orm.hibernate4.LocalSessionFactoryBean; 
import org.springframework.transaction.annotation.EnableTransactionManagement; 

import javax.sql.DataSource; 
import java.util.Properties; 

@Configuration 
@EnableTransactionManagement 
@ComponentScan({ "com.egs.account.config" }) 
@PropertySource(value = { "classpath:application.properties" }) 
public class HibernateConfiguration { 

    @Autowired 
    private Environment environment; 

    @Bean 
    public LocalSessionFactoryBean sessionFactory() { 
     LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 
     sessionFactory.setDataSource(dataSource()); 
     sessionFactory.setPackagesToScan(new String[] { "com.egs.account" }); 
     sessionFactory.setHibernateProperties(hibernateProperties()); 
     return sessionFactory; 
    } 

    @Bean 
    public DataSource dataSource() { 
     DriverManagerDataSource dataSource = new DriverManagerDataSource(); 
     dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName")); 
     dataSource.setUrl(environment.getRequiredProperty("jdbc.url")); 
     dataSource.setUsername(environment.getRequiredProperty("jdbc.username")); 
     dataSource.setPassword(environment.getRequiredProperty("jdbc.password")); 
     return dataSource; 
    } 

    private Properties hibernateProperties() { 
     Properties properties = new Properties(); 
     properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect")); 
     properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql")); 
     properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql")); 
     return properties;   
    } 

    @Bean 
    @Autowired 
    public HibernateTransactionManager transactionManager(SessionFactory s) { 
     HibernateTransactionManager txManager = new HibernateTransactionManager(); 
     txManager.setSessionFactory(s); 
     return txManager; 
    } 
} 

をあるの取得と思うによる先ののgetSession()メソッドを呼び出して、私は私のユーザードメインを保持しようとしたとき、私はそのような例外を取得します。

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread 

誰も私にこの例外の理由を教えてもらえますか?

答えて

0

私はすでに私の質問の答えを見つけました。 理由は、XMLファイルの1つに "dataSource"という名前のBeanが宣言されていて、 "HibernateConfiguration"ファイルに "dataSource"設定メソッドが存在するため、それらの間に競合がありました。

関連する問題