2011-03-29 115 views
7

我遇到了一個奇怪的問題,當我嘗試編譯一個DTO文件,它有映射到數據庫的休眠註釋。當失敗與下面一個奇怪的消息日誌。 什麼可能是這個問題的原因?我想這個錯誤來自於CashDTO文件。我在文件CashDTO.java中做了什麼錯誤?hibernate註釋編譯錯誤

import java.io.Serializable; 
import java.math.BigDecimal; 
import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.FetchType; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.Table; 
import javax.persistence.TableGenerator; 
import javax.persistence.Version; 
import org.hibernate.annotations.Cache; 
import org.hibernate.annotations.CacheConcurrencyStrategy; 

    /** 
    * @author othmanelmoulat 
    * 
    */ 
    @Entity 
    @TableGenerator(name = "cash_GEN", table = "jbilling_seqs", pkColumnName = "name", valueColumnName = "next_id", pkColumnValue = "cash", allocationSize = 100) 
    @Table(name = "cash") 
    public class CashDTO implements Serializable { 
     int id; 
     BigDecimal amount; 
     Date date; 
     int versionNum; 

     public CashDTO() { 
      super(); 
      // TODO Auto-generated constructor stub 
     } 

     public CashDTO(int id) { 
      super(); 
      this.id = id; 
     } 

     public CashDTO(int id, BigDecimal amount, Date date) { 
      super(); 
      this.id = id; 
      this.amount = amount; 
      this.date = date; 
     } 

     public CashDTO(int id, BigDecimal amount, Date date, int versionNum) { 
      super(); 
      this.id = id; 
      this.amount = amount; 
      this.date = date; 
      this.versionNum = versionNum; 
     } 

     @Id 
     @GeneratedValue(strategy = GenerationType.TABLE, generator = "cash_GEN") 
     @Column(name = "id", unique = true, nullable = false) 
     public int getId() { 
      return this.id; 
     } 

     public void setId(int id) { 
      this.id = id; 
     } 
     @Column(name = "amount", nullable = false) 
     public BigDecimal getAmount() { 
      return amount; 
     } 

     public void setAmount(BigDecimal amount) { 
      this.amount = amount; 
     } 
     @Column(name = "date", nullable = false) 
     public Date getDate() { 
      return date; 
     } 

     public void setDate(Date date) { 
      this.date = date; 
     } 
     @Version 
     @Column(name = "OPTLOCK") 
     public int getVersionNum() { 
      return versionNum; 
     } 

     public void setVersionNum(int versionNum) { 
      this.versionNum = versionNum; 
     } 

    } 

錯誤日誌:

Buildfile: /Users/othmanelmoulat/Documents/workspace/jbilling/src/build.xml 

init: 
    [delete] Deleting directory /Users/othmanelmoulat/Documents/workspace/jbilling/src/build/test-results 
    [mkdir] Created dir: /Users/othmanelmoulat/Documents/workspace/jbilling/src/build/test-results 

compile_api: 
    [javac] /Users/othmanelmoulat/Documents/workspace/jbilling/src/build.xml:272: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 

findRevision: 

jar_api: 
     [jar] Building jar: /Users/othmanelmoulat/Documents/workspace/jbilling/src/build/deploy/jbilling_api.jar 

test-ws: 
    [javac] /Users/othmanelmoulat/Documents/workspace/jbilling/src/build.xml:457: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 
    [javac] Compiling 7 source files to /Users/othmanelmoulat/Documents/workspace/jbilling/src/build/test 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'name()' in type 'javax.persistence.TableGenerator': class file for javax.persistence.TableGenerator not found 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'table()' in type 'javax.persistence.TableGenerator' 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'pkColumnName()' in type 'javax.persistence.TableGenerator' 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'valueColumnName()' in type 'javax.persistence.TableGenerator' 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'pkColumnValue()' in type 'javax.persistence.TableGenerator' 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'allocationSize()' in type 'javax.persistence.TableGenerator' 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'name()' in type 'javax.persistence.Table': class file for javax.persistence.Table not found 
    [javac] com/sapienter/jbilling/server/user/db/CashDTO.class(com/sapienter/jbilling/server/user/db:CashDTO.class): warning: Cannot find annotation method 'strategy()' in type 'javax.persistence.GeneratedValue': class file for javax.persistence.GeneratedValue not found 
    [javac] An exception has occurred in the compiler (1.6.0_24). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. 
    [javac] com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.persistence.GenerationType not found 

BUILD FAILED 
/Users/othmanelmoulat/Documents/workspace/jbilling/src/build.xml:457: Compile failed; see the compiler error output for details. 

Total time: 5 seconds 
+0

這是編譯器中的bug造成的 - http://bugs.java.com/view_bug.do?bug_id=6550655 – fnt 2014-12-06 16:19:13

回答

5

聽起來像是javax.persistence類不在javac任務在你的test-ws Ant目標的類路徑。

+0

hmm很奇怪!在我添加類CashDTO之前,test-ws已成功運行,CashDTO與我的代碼中的其他舊DTO沒有區別。爲什麼只有類CashDTO抱怨它而不是其他DTO類與CashDTO非常相似? – othman 2011-03-30 00:04:52

+0

對不起,你沒錯。我不應該在我的test-ws中使用hibernate註釋的DTO。我必須創建另一個DTO來與test-ws一起使用。 – othman 2011-03-30 00:23:47

+0

但是爲什麼javac在類路徑中默認沒有它們,那是我的問題? javac本身位於JDK c:\ Program Files(x86)\ Java \ jdk1.6.0_26 \ bin \ javac.exe中,所以它不應該找到它們嗎? (對於追隨者,這是我的修補程序:http://betterlogic.com/roger/2011/07/javachibernate-woe/ comment 1 – rogerdpack 2011-07-12 18:33:12