Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How to generate the PK?

Hi Tanujit,

This should work provided the db supports identity (SQLServer, DB2 etc) and "CertKeyfield" is defined as Identity field in the table.
Also Eclipselink should use correct db platform (SQLServerPlatform, DB2Platform etc.) - you may need to explicitly specify it in persistence.xml or pass to createEMF.
The property is called "eclipselink.target-database", please see org.eclipse.persistence.config.TargetDatabase for supported db platforms,

Thanks,
Andrei
On 8/13/2010 4:11 PM, Tanujit Chowdhury wrote:
Hi,
I have an object that is representing a Table. It has a numeric primary key and each time a record is created it is incremented by 1.
How to define this in the Object mapping?

I have used the following:
@Entity
@Table(name = "vmlo.certificate")
public class Certificate implements Serializable {
    private static final long serialVersionUID = 1L;
    private int certKeyfield;
    private String certBrowserName;

    public Certificate() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CertKeyfield")
    public int getCertKeyfield() {
        return this.certKeyfield;
    }

    public void setCertKeyfield(int certKeyfield) {
        this.certKeyfield = certKeyfield;
    }
.
.
Using this I am getting an exception from my JPA provider EclipseLink:
<Error> <EJB> <BEA-010026> <Exception occurred during commit of transaction Name=[EJB com.thunderhead.simple.SimpleBean.process(int)],Xid=BEA1-0660A26EF337BD76B51F(9378830),Status=Rolled back. [Reason=weblogic.transaction.internal.AppSetRollbackOnlyException],numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=0,seconds left=60,SCInfo[wl_server+examplesServer]=(state=rolledback),properties=({weblogic.transaction.name=[EJB com.thunderhead.simple.SimpleBean.process(int)]}),OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(CoordinatorURL=examplesServer+192.168.2.165:7001+wl_server+t3+, XAResources={examples-demoXA, WLStore_wl_server_WseeFileStore, examples-demoXA-2, WLStore_wl_server_exampleJDBCStore, examples-multiDataSource-demoXAPool, WLStore_wl_server__WLS_examplesServer},NonXAResources={})],CoordinatorURL=examplesServer+192.168.2.165:7001+wl_server+t3+): weblogic.transaction.RollbackException: Unknown reason
at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1818)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:333)

It does not explain the reason for exception. However, is it due to the reason that the PK generation is not happening or the EclipseLink does not know how to generate this PK? Is the GenerationType.IDENTITY is wrong to generate PK for this type?

Please help.

--
Tanujit Chowdhury

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top