JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping » Hibernate  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Table per concrete class with implicit polymorphism 方式映射發生 org.hibernate.hql.ast.QuerySyntaxExceptio
tai1110





發文: 157
積分: 0
於 2010-03-01 12:03 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請各位大大幫看一下我設定那邊錯誤
直接存取 HeaderDefaultM 的話會 HeaderDefaultM is not mapped
可是在 hibernate.cfg.xml 有設說 …
不過在存取 Header001M & Header002M 都是很正常的

Hibernate 3.3.1.GA
Hibernate Annotations 3.4.0.GA

SuperClass
1
2
3
@MappedSuperclass
public abstract class HeaderDefaultM<T1 extends HeaderDefaultM<T1, T2>, T2 extends ProcessDefaultM<T1, T2>> {
}


Subclass 1
1
2
3
4
5
6
7
8
9
10
@Entity
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "HEADER001_S")
@Table(name = "HEADER001")
public class Header001M
    extends
    HeaderDefaultM<Header001M, Process001M> {
 
  public Header001M() {
  }
}


Subclass 2
1
2
3
4
5
6
7
8
9
10
@Entity
@SequenceGenerator(name = "SEQ_STORE", sequenceName = "HEADER002_S")
@Table(name = "HEADER002")
public class Header002M
    extends
    HeaderDefaultM<Header002M, Process002M> {
 
  public Header002M() {
  }
}


hibernate.cfg.xml
1
2
3
4
5
...
    <mapping class="HeaderDefaultM" />
    <mapping class="Header001M" />
    <mapping class="Header001M" />
...


存取資料的 Code
1
2
3
4
5
6
7
8
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
String qryString = "from HeaderDefaultM header";
Query qry = s.createQuery(from HeaderDefaultM header);
 
List<HeaderDefaultM> allHeader = qry.list();
for(HeaderDefaultM o: allHeader) {
  System.out.println("Header: " + o.getHeaderId());
}


Error
1
org.hibernate.hql.ast.QuerySyntaxException: HeaderDefaultM is not mapped [from HeaderDefaultM header]


tai1110 edited on 2010-03-01 13:18
reply to postreply to post
» JWorld@TW »  Object Relational Mapping » Hibernate

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8