These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem with Oracle sequence generator in a SubClass
PostPosted: Tue May 05, 2009 4:57 am 
Newbie

Joined: Tue May 05, 2009 4:27 am
Posts: 3
Hi all,

I'm using Hibernate annotation to generate sequence number in Oracle 10g database, but i get this error message while trying to insert to the SubClass:

"Unable to insert to TrxLog Header: org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value"

Here, i use a class TrxLog and sub class ExtendedTrxLog, here's part of the structure:

Quote:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "dType", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "0")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TrxLog implements Serializable {
private int id;
private String trxCode;

@Id
@SequenceGenerator(name = "id_sequence", sequenceName = "sq50")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "id_sequence")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTrxCode() {
return trxCode;
}
public void setTrxCode(String trxCode) {
this.trxCode = trxCode;
}
}

@Entity
@DiscriminatorValue(value="5")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ExtendedTrxLog extends TrxLog {
private double amount;

public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}


There's also a trigger for TrxLog table

Quote:
BEGIN
if :NEW.ID is null
then SELECT sq50.nextval INTO :NEW.ID FROM dual;
end if;
END;


Any idea? sory for any mistakes, I'm still a newbie here

Thanks,
Felix


Top
 Profile  
 
 Post subject: Re: Problem with Oracle sequence generator in a SubClass
PostPosted: Tue May 05, 2009 5:10 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
You are using wrong inheritance strategy. correct
Code:
@Inheritance(strategy = InheritanceType.JOINED)
to
Code:
@Inheritance(strategy = InheritanceType.SINGLE_TABLE))


Top
 Profile  
 
 Post subject: Re: Problem with Oracle sequence generator in a SubClass
PostPosted: Tue May 05, 2009 5:34 am 
Newbie

Joined: Tue May 05, 2009 4:27 am
Posts: 3
I use 1 table for each class here, so if i use InheritanceType.SINGLE_TABLE, fields from secondary table are not found.

here's the error:
Quote:
17:23:34,486 WARN [JDBCExceptionReporter] SQL Error: 904, SQLState: 42000
17:23:34,486 ERROR [JDBCExceptionReporter] ORA-00904: "TRXLOG0_"."VOUCHERCODE":
invalid identifier


field voucherCode is in ExtendedTrxLog table, with ExtendedTrxLog entity


Top
 Profile  
 
 Post subject: Re: Problem with Oracle sequence generator in a SubClass
PostPosted: Wed May 06, 2009 12:56 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
I got confused with
Quote:
@DiscriminatorColumn(name = "dType", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "0")
because these mapping uses with
Quote:
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
.

As you mentioned that you are using table per class, so mapping
Quote:
@Inheritance(strategy = InheritanceType.JOINED)
is correct. But subclass should be mapped differently.
Sample code is as below
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
//@DiscriminatorColumn(name = "dType", discriminatorType = DiscriminatorType.INTEGER)
//@DiscriminatorValue(value = "0")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TrxLog implements Serializable {
private int id;
private String trxCode;

@Id
@SequenceGenerator(name = "id_sequence", sequenceName = "sq50")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "id_sequence")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTrxCode() {
return trxCode;
}
public void setTrxCode(String trxCode) {
this.trxCode = trxCode;
}
}

@Entity
//@DiscriminatorValue(value="5")
@PrimaryKeyJoinColumn(name = "primary_key_of_ExtendedTrxLog")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ExtendedTrxLog extends TrxLog {
private double amount;

public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}


you have to find out how to mapped column which you defined with @DiscriminatorColumn


Top
 Profile  
 
 Post subject: Re: Problem with Oracle sequence generator in a SubClass
PostPosted: Thu Jun 04, 2009 12:35 am 
Newbie

Joined: Tue May 05, 2009 4:27 am
Posts: 3
This case is already closed, the problem is from different table not connected to this trxLog, it's not mentioned anywhere in the application log though, so it was so hard to be found.

The solution is to add @SequenceGenerator annotation to that class (since I use oracle), so it should look like this:
Quote:
@Id
@SequenceGenerator(name = "id_sequence", sequenceName = "sq50")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "id_sequence")
public int getId() {
return id;
}


Thanks for all your help guys, I think I learn something from this


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.