I am unable to create hibernate session in 0.7.1. I know I am not creating hibernate session right. But cant figure out where am I going wrong. Any help will be appreciated.
ERROR:
! org.hibernate.HibernateException: No session currently bound to execution context
! at org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75) ~[userengine-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
! at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) ~[userengine-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
The Application file:
public class UserEngineApplication extends Application<UserEngineConfiguration>{
public static void main(String[] args) throws Exception {
new UserEngineApplication().run(args);
}
private final HibernateBundle<UserEngineConfiguration> hibernateBundle =
new HibernateBundle<UserEngineConfiguration>(Persons.class) {
@Override
public DataSourceFactory getDataSourceFactory (UserEngineConfiguration configuration)
{
return configuration.getDataSourceFactory();
}
};
@Override
public void initialize(Bootstrap<UserEngineConfiguration> bootstrap) {
bootstrap.addBundle(hibernateBundle);
}
@Override
public void run(UserEngineConfiguration configuration, Environment environment) throws Exception {
final PersonDAO personsdao = new PersonDAO(hibernateBundle.getSessionFactory());
environment.jersey().register(new PersonsResource(personsdao));
}
}
The Configuration file:
public class UserEngineConfiguration extends Configuration {
@Valid
@NotNull
@JsonProperty
private DataSourceFactory database = new DataSourceFactory();
@JsonProperty("database")
public DataSourceFactory getDataSourceFactory() {
return database;
}
@JsonProperty("database")
public void setDataSourceFactory(DataSourceFactory dataSourceFactory)
{
this.database = dataSourceFactory;
}
}
YAML file:
database:
driverClass: org.postgresql.Driver
user: user
password: pass
url: jdbc:postgresql://localhost:5432/Tryout
Some links that I tried:
https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example .
在资源方法上添加@UnitOfWork
批注后,它可以工作。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.