2011-02-05 46 views
1

我想问你一个关于字节数组是否属于play framework模型的问题。我的模型的定义是这样的:Play框架模型中的数组[Byte]

@Entity 
class BTFile (
    @Required 
    var hash : Array[Byte], 

    @Required 
    var size : Int 

) extends Model { 

    @OneToMany(mappedBy="file",cascade=Array(CascadeType.ALL)) 
    var peers:JList[BTPeer] = new ArrayList[BTPeer] 
} 

随着DAO对象定义为

object BTFiles extends QueryOn[BTFile] 

但每次我尝试使用BTFiles.find( “byHash”)时,它抛出以下异常:

[B cannot be cast to [Ljava.lang.Object; 

有谁知道如何解决这个问题?我试图谷歌它,但我没有找到解决办法。我测试它的单元测试:

it should "create and retrieve BTFile" in { 
    val file = new BTFile("some_hash".getBytes,1).save 

    BTFiles.find("byHash","some_hash".getBytes) 

} 

任何帮助将不胜感激!

+0

你可以添加堆栈跟踪吗? – 2011-02-05 13:23:32

回答

1

我建议您尝试使用java.lang.Byte,因为Array不是类型擦除,并因此而Array[Byte]不能转换成Array[Object]