error while saving the value in DB, I can able to get the value from DB(one column I have manually inserted with ACCOUNTSUBSCRIPTIONKEY value as 1) but not able to save the value.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value;
SQL [select ACCOUNTSUBSCRIPTION_PK.nextval from dual];
nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
Table:
CREATE SEQUENCE ACCOUNTSUBSCRIPTION_PK
/
----------------------------------------
-- TABLE: ACCOUNTSUBSCRIPTIONS
----------------------------------------
CREATE TABLE ACCOUNTSUBSCRIPTIONS (
ACCOUNTSUBSCRIPTIONKEY NUMBER NOT NULL,
KEY NUMBER NOT NULL,
EMAIL VARCHAR2(128 CHAR) NOT NULL,
XEMAIL VARCHAR2(128 CHAR) ,
DBTIMESTAMP TIMESTAMP (6) DEFAULT systimestamp NOT NULL,
CONSTRAINT XPKACCOUNTSUBSCRIPTION PRIMARY KEY (ACCOUNTSUBSCRIPTIONKEY) USING INDEX INITRANS 20 TABLESPACE IDX
)
AccountSubscriptions.class:
@Entity
@Table(name = "ACCOUNTSUBSCRIPTIONS")
public class AccountSubscriptions implements Serializable{
private static final long serialVersionUID = 4399781893670770594L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence")
@SequenceGenerator(name="sequence", sequenceName = "ACCOUNTSUBSCRIPTION_PK", allocationSize=1)
@Column(name = "ACCOUNTSUBSCRIPTIONKEY")
private Long accountSubscriptionKey;
@Column(name = "KEY")
private Long key;
@Column(name = "EMAIL", length = 128)
private String email;
@Column(name = "XEMAIL", length = 128)
private String xEmail;
public AccountSubscriptions() {
}
public AccountSubscriptions(Long Key, String email, String xEmail) {
this.Key = Key;
this.email = email;
this.xEmail = xEmail;
}
public Long getAccountSubscriptionKey() {
return accountSubscriptionKey;
}
public void setAccountSubscriptionKey(Long accountSubscriptionKey) {
this.accountSubscriptionKey = accountSubscriptionKey;
}
public Long getKey() {
return key;
}
public void setKey(Long key) {
this.key = key;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getXemail() {
return xEmail;
}
public void setXemail(String xEmail) {
this.xEmail = xEmail;
}
@Override
public int hashCode() {
int result = this.email != null ? this.email.hashCode() : 0;
result = 31 * result + (this.xEmail != null ? this.xEmail.hashCode() : 0);
result = 31 * result + (this.accountKey != null ? this.accountKey.hashCode() : 0);
return result;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o != null && this.getClass() == o.getClass()) {
AccountSubscriptions that;
label57: {
that = (AccountSubscriptions)o;
if (this.email != null) {
if (this.email.equals(that.email)) {
break label57;
}
} else if (that.email == null) {
break label57;
}
return false;
}
label50: {
if (this.xEmail != null) {
if (this.xEmail.equals(that.xEmail)) {
break label50;
}
} else if (that.xEmail == null) {
break label50;
}
return false;
}
if (this.key != null) {
if (!this.key.equals(that.key)) {
return false;
}
} else if (that.key != null) {
return false;
}
return true;
} else {
return false;
}
@Override
public String toString() {
return "AccountSubscriptions{" +
", key=" + key +
", email='" + email + ''' +
", xEmail='" + xEmail + ''' +
'}';
}
}
Account.hbm.xml
<class name="com.citrix.g2w.services.subscription.domain.AccountSubscriptions" table="ACCOUNTSUBSCRIPTIONS">
<id name="accountSubscriptionKey" type="long" access="field" >
<column name="ACCOUNTSUBSCRIPTIONKEY" />
<generator class="sequence">
<param name="sequence">ACCOUNTSUBSCRIPTION_PK</param>
</generator>
</id>
<natural-id>
<property name="key" >
<column name="KEY" />
</property>
<property name="email" >
<column name="EMAIL" />
</property>
<property name="xEmail" >
<column name="XEMAIL" />
</property>
</natural-id>
</class>
As I am new to hibernate, I have some open Questions:
- Why it is not getting sequence value? I can see in Oracle DB sequence is created.
- If we are declare the value in Account.hbm.xml then is it required to use @Entity, @Table , @ID, @Generator, @sequence ,@column etc in class?