Announcement Announcement Module
Collapse
No announcement yet.
Spring JPA Hibernate Oracle Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JPA Hibernate Oracle

    Hi,

    I am using spring, with Hibernate and having problems with Oracle sequences. The first time I insert a record, it works fine ( since the ID is set to 0). So it looks like it is not using the sequence at all. The next time, it fails with a unique constraint violation as it is still trying to insert a record with a 0 in it . Any help would be appreciated! Thanks!

    Here is my code:

    @Entity
    @SequenceGenerator(name="applUserSeq", sequenceName="SIM.S_APPL_USER_ID", allocationSize=1)
    @Table(name="APPL_USER")
    public class ApplicationUser implements Serializable {
    @Id
    @Column(name="APPL_USER_ID")
    private long applUserId;

    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="applUserSeq")
    public long getApplUserId() {
    return applUserId;
    }


    appicationContext.xml:

    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
    <bean
    class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="databasePlatform" value="org.hibernate.dialect.Oracle9Dialect" />
    <property name="database" value="ORACLE" />
    <property name="showSql" value="true" />
    </bean>
    </property>
    </bean>

  • #2
    Hello,

    I'm new to JPA but I don't think Hibernate supports mixing annotation placement. Try putting your @GeneratedValue(...) annotation on the field instead of the getter.

    Dustin

    Comment


    • #3
      Thank you! That worked!

      Comment

      Working...
      X