Hallo!
Ist es möglich mit Hibernate Views zu behandeln? Ich versuche nämlich gerade eine View wie eine Tabelle zu behandeln, jedoch klappt irgendetwas nicht..
Hier mal der code:
Model:
Mapping dazu:
query:
1. Wie soll man den primärschlüssel versorgen wenn die View keinen besitzt?
2. im mapping file: table=view_name?
WEnn ich die Query von oben ausführe bekomme ich die ausfürhliche meldung:
sehr aussagekräftig..
Ist es möglich mit Hibernate Views zu behandeln? Ich versuche nämlich gerade eine View wie eine Tabelle zu behandeln, jedoch klappt irgendetwas nicht..
Hier mal der code:
Model:
Code:
public class LocationPortalModel {
/** district */
private String district;
/** borough number */
private Integer boroughNumber;
/** borough description */
private String boroughDescription;
/** collector localtiy */
private Integer collectorLocaltity;
/** locality number */
private Integer localityNumber;
/** address */
private String address;
/** zip code */
private Integer zip;
/** locality */
private String locality;
/** case type */
private String caseType;
/** case count */
private Integer count;
/** case quality sort */
private String qualityKind;
/** dbk from E_30019 */
private String dbk;
/** geo mercato coordiante x */
private Integer geoMercX;
/** geo mercato coordiante y */
private Integer geoMercY;
/** quality of the geo data */
private Integer geoQuality;
/** dbk from E_30021 */
private String id;
public LocationPortalModel() {
// nothing to do
}
public LocationPortalModel(final String district, final Integer boroughNumber, final String boroughDescription,
final Integer collectorLocaltity, final Integer localityNumber, final String address, final Integer zip,
final String locality, final String caseType, final Integer count, final String qualityKind,
final String dbk, final Integer geoMercX, final Integer geoMercY, final Integer geoQuality,
final String id) {
this.district = district;
this.boroughNumber = boroughNumber;
this.boroughDescription = boroughDescription;
this.collectorLocaltity = collectorLocaltity;
this.localityNumber = localityNumber;
this.address = address;
this.zip = zip;
this.locality = locality;
this.caseType = caseType;
this.count = count;
this.qualityKind = qualityKind;
this.dbk = dbk;
this.geoMercX = geoMercX;
this.geoMercY = geoMercY;
this.geoQuality = geoQuality;
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getBoroughDescription() {
return boroughDescription;
}
public void setBoroughDescription(String boroughDescription) {
this.boroughDescription = boroughDescription;
}
public Integer getBoroughNumber() {
return boroughNumber;
}
public void setBoroughNumber(Integer boroughNumber) {
this.boroughNumber = boroughNumber;
}
public String getCaseType() {
return caseType;
}
public void setCaseType(String caseType) {
this.caseType = caseType;
}
public Integer getCollectorLocaltity() {
return collectorLocaltity;
}
public void setCollectorLocaltity(Integer collectorLocaltity) {
this.collectorLocaltity = collectorLocaltity;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public String getDbk() {
return dbk;
}
public void setDbk(String dbk) {
this.dbk = dbk;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getLocality() {
return locality;
}
public void setLocality(String locality) {
this.locality = locality;
}
public Integer getLocalityNumber() {
return localityNumber;
}
public void setLocalityNumber(Integer localityNumber) {
this.localityNumber = localityNumber;
}
public String getQualityKind() {
return qualityKind;
}
public void setQualityKind(String qualityKind) {
this.qualityKind = qualityKind;
}
public Integer getZip() {
return zip;
}
public void setZip(Integer zip) {
this.zip = zip;
}
public Integer getGeoMercX() {
return geoMercX;
}
public void setGeoMercX(Integer geoMercX) {
this.geoMercX = geoMercX;
}
public Integer getGeoMercY() {
return geoMercY;
}
public void setGeoMercY(Integer geoMercY) {
this.geoMercY = geoMercY;
}
public Integer getGeoQuality() {
return geoQuality;
}
public void setGeoQuality(Integer geoQuality) {
this.geoQuality = geoQuality;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Mapping dazu:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="at.pcd.wam.technologie.persistence.model">
<class name="at.pcd.wam.technologie.persistence.model.LocationPortalModel" table="V_STANDORT_PORTAL" >
<id name="id" type="string" column="E_30021_DBK">
<generator class="assigned"></generator>
</id>
<property name="dbk" type="string" column="E_30019_DBK"></property>
<property name="district" type="string" column="BEZIRK"></property>
<property name="boroughNumber" type="integer" column="GEMEINDE_NR"></property>
<property name="boroughDescription" type="string" column="GEMEINDE_BEZ"></property>
<property name="collectorLocaltity" type="integer" column="SAMMLER_STANDORT"></property>
<property name="localityNumber" type="integer" column="STANDORT"></property>
<property name="address" type="string" column="ADR"></property>
<property name="zip" type="integer" column="PLZ"></property>
<property name="locality" type="string" column="ORT"></property>
<property name="caseType" type="string" column="BEH_TYP"></property>
<property name="count" type="integer" column="ANZAHL"></property>
<property name="qualityKind" type="string" column="QSORTE"></property>
<property name="geoMercX" type="integer" column="GEO_MERC_X"></property>
<property name="geoMercY" type="integer" column="GEO_MERC_Y"></property>
<property name="geoQuality" type="integer" column="GEO_QUALITY"></property>
</class>
</hibernate-mapping>
query:
Code:
StringBuilder sb = new StringBuilder();
sb.append("FROM LocationPortalModel");
Session session = HibernateUtil.getCurrentSession();
Transaction tx = null;
ArrayList<LocationPortalModel> values = null;
try {
tx = session.beginTransaction();
/* load data */
values = (ArrayList<LocationPortalModel>) session.createQuery(sb.toString()).list();
// values = (ArrayList<LocationPortalModel>) session.createSQLQuery(sb.toString()).list();
tx.commit();
1. Wie soll man den primärschlüssel versorgen wenn die View keinen besitzt?
2. im mapping file: table=view_name?
WEnn ich die Query von oben ausführe bekomme ich die ausfürhliche meldung:
Code:
org.hibernate.exception.SQLGrammarException: could not execute query