Already value [org.springframework.orm.hibernate5.SessionHolder@485d518f] for key [org.hibernate.internal.SessionFactoryImpl@29375882] bound to thread [http-bio-2016-exec-6]
No value for key [org.hibernate.internal.SessionFactoryImpl@29375882] bound to thread [http-bio-2016-exec-6]
实体
@Entity
@Table(name = "register")
public class Register{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "uname")
@Size(min = 4, max = 10)
private String uname;
@Column(name = "password")
@Size(min = 4, max = 8)
private String password;
@Column(name = "email")
@NotEmpty
@Email
private String email;
@Column(name = "age")
@NotNull
@Min(10)
@Max(40)
private String age;
@Column(name = "dob")
@NotNull
@Past
private String dob;
@Column(name = "country")
@NotEmpty
private String country;
// setters and getters
public String getUname() {
System.out.println("control is in getUname method");
return uname;
}
public void setUname(String uname) {
System.out.println("control is in getUname method");
this.uname = uname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
System.out.println("control is in getPassword");
this.email = email;
}
public String getAge() {
return age;
}
public void setAge(String age) {
System.out.println("control is in setAge method");
this.age = age;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
Context XML
<context:component-scan base-package="com.spring" />
<tx:annotation-driven />
<context:annotation-config />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/usersdb" />
<property name="username" value="root" />
<property name="password" value="90141139" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<list>
<value>com.spring.model.Register</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="jdbc.fetch_size">20</prop>
<prop key="jdbc.batch_size">25</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.autoReconnect">true</prop>
<prop key="connection.autoReconnectForPools">true</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
答案 0 :(得分:0)
谢谢各位接受我的问题我通过在我的dao类之上使用注释@Transactional(propagation = Propagation.REQUIRED,re adOnly = false)解决了错误谢谢