Hi All!
I have 1 table of objects.
First: in search mode - need to show only name and text property,
Then: in browse/edit mode - need to show name, text, type, datecreate and others.
Here're java entities:
Base object:Code:
@Entity
abstract class Key {
@Id
@Column(name = "id")
UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}
Link object for search mode:Code:
@Entity
public class Link extends Key {
@Column(name = "name")
private String name;
@Lob
@Column(name = "text")
private String text;
public String getName() {
return name;
}
public String getText() {
return text;
}
}
Full object for browse/eit mode:Code:
@Entity
public class Document extends Link{
@Column(name = "type")
private String type;
public String getType() {
return type;
}
.....
}
And 2 differnet SQL queries for each object:
1. SELECT d.id, d.name, (CASE WHEN LENGTH(d.text) > 170 THEN SUBSTRING(d.text, 1, 170, CODEUNITS16)||'<b>...</b>' ELSE d.text END) text FROM DLib.dl_documents d2. SELECT d.id, d.name, d.text, d.type, d.datecreate FROM DLib.dl_documents dSuch way hibernate can't extends class Document from Doclink (f.e. during executing SQL №1 - throws and error of uknown field(s))
Quote:
db.createSQLQuery(sql).addEntity(Link.class);
But if there's another base class(abstract) with all properties of class Doclink, and classes Doclink and Document extends from it - all works.
Code:
@Entity
abstract class Link extends Key {
@Column(name = "name")
private String name;
@Lob
@Column(name = "text")
private String text;
public String getName() {
return name;
}
public String getText() {
return text;
}
}
public class Doclink extends Link{} -- this class has no different properties from abstract parent
public class Document extends Link{}
Is it possible to map 2 classes (one extends from another) from single table with hibernate? Maybe there's example with Discriminator columns..
Dev settings:
JDK 1.7
Hibernate 4.1.7
DataBase: DB2 9.7
Thanks.