5

I have a single entity object A which map 1 to 1 with the table and another entity object "AjoinB" extended from the single entity object and join with another entity object. I'm getting this "DTYPE" invalid identifier as a result of this. Below is an example

@Entity
@Table(name="TableA")
@NamedQuery(...)
public class A implements Serializable{
@EmbeddedId
private ABC id;
@Column(name="...")
//getters/setters

@Entity
@Table(name="TableA")
@NameQuery(...)
public class AjoinB extends A{
@OneToOne
@JoinColumn({...}
private B b;
//gettter/setters

Does anybody know how to fix the problem. I know doing inheritance stuff would generate that DTYPE but my table doesn't have that column :(

To be more clear, can I have a single table inheritance without discriminator column? it makes no sense to have discriminator column in my entity

SpyClown
  • 199
  • 1
  • 1
  • 14
  • If you have "single table inheritance without discriminator" how do you expect the persistence mechanism to determine what object type each row is? by magic? – Neil Stockton Mar 02 '16 at 07:52
  • This is not about inheritance. JPA treats it as inheritance because I extended from a parent class. Here is the problem 1. I create entity A (single entity and someone might use this) 2. I want to have another entity called A-joined that is identical to A except it includes an association 3. I don't want to have duplicates fields in A-joined so I extended from A 4. Now JPA thinks this is single table inheritance. This is not about Car and type of car problem. – SpyClown Mar 02 '16 at 14:18
  • JPA "thinks" something is single table inheritance if you have class inheritance of entities and you don't define the inheritance strategy of the root class to be something other than single table. – Neil Stockton Mar 02 '16 at 16:30

3 Answers3

4

It's hard to diagnose without the complete stacktrace, but as you probably already know, the API docs say:

If the @DiscriminatorColumn annotation is missing, and a discriminator column is required, the name of the discriminator column defaults to "DTYPE" and the discriminator type to DiscriminatorType.STRING.

Other answers (also here) suggest that adding an explicit @DiscriminatorColumn can potentially solve the problem. However I'd be the first to admit there doesn't seem to be a conclusive, generic answer.

Community
  • 1
  • 1
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • It didn't work. I did a lot of research before i post my question. If I use `@DiscriminatorColumn` that doesn't exist in the table, it would still complaining that it cannot find that column name. I wonder if I could use `@DiscriminatorColumn` as an existing column in the database – SpyClown Mar 02 '16 at 03:05
2

I found the solution here EclipseLink JPA inheritance without discriminator column

Community
  • 1
  • 1
SpyClown
  • 199
  • 1
  • 1
  • 14
0

Another possible reason, it could be that you have in the code a similar or repeated class that has the same attributes (or columns) and hibernate adds the DTYPE column as a way to differentiate them.

For example a possible error for this case would be something like:

could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception java.sql.SQLSyntaxErrorException: ORA-00904: .DTYPE: invalid identifier.