Я пытался импортировать образец проекта в eclipse и столкнулся с приведенной ниже ошибкой при запуске приложения.
Caused by: org.hibernate.MappingException: org.hibernate.dialect.OracleDialect does not support identity key generation
at org.hibernate.dialect.Dialect.getIdentityColumnString(Dialect.java:743)
at org.hibernate.dialect.Dialect.getIdentityColumnString(Dialect.java:733)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:426)
at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:1028)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:125)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:492)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 32 more
В соответствии с этой ссылкой SO, я изменил
@GeneratedValue(strategy = GenerationType.IDENTITY)
to
@GeneratedValue(strategy = GenerationType.AUTO)
или @GeneratedValue(strategy = GenerationType.TABLE)
Но это не сработало.
Вот код:
User.java:
@Entity
@Table(name = "users")
@ManagedBean
@ViewScoped
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "role", nullable = false)
private String role;
public int getId() {
return id;
}
public void setId(int 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 getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
Из приложенияContext.xml:
<!-- Session Factory Declaration -->
<bean id="SessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="annotatedClasses">
<list>
<value>com.crud.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>