发现了一些有趣的事情 关于这个问题。
我的应用程序中有这个 < code> 模式 < /code> 类 :
@Entity
@Table(name="users")
class User extends Model{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_id_seq")
@Column(name="id", updatable=false, nullable=false)
val id:Long = 0L
@BeanProperty var name:String = _
@BeanProperty var email:String = _
时 时
此类编译为名为 User
的 java 类, 其定义如下:
@Entity
@Table(name="users")
@ScalaSignature(bytes=long array of bytes)
public class User extends Model
implements ScalaObject, EntityBean
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_id_seq")
@Column(name="id", updatable=false, nullable=false)
private final long id;
private String name;
private String email;
private volatile int bitmap$init$0;
private static String _EBEAN_MARKER = "models.User";
...
public long id()
{
if ((_ebean_get_bitmap$init$0() & 0x1) != 0)
{
_ebean_get_id(); return _ebean_get_id();
时 时
throw new
UninitializedFieldError("Uninitialized field: User.scala: 17".toString());
时 时
public String name()
{
if ((_ebean_get_bitmap$init$0() & 0x2) != 0)
{
_ebean_get_name(); return _ebean_get_name();
时 时 throw new
UninitializedFieldError("Uninitialized field: User.scala: 19".toString());
时 时
public void name_$eq(String paramString) {
_ebean_set_name(paramString);
_ebean_set_bitmap$init$0(_ebean_get_bitmap$init$0() | 0x2);
时 时
....
The bitmap$init$0
actually comes from a class enhancement, and I thought that the responsible was the Ebean
library, which I m currently using. But after reading your post I went to investigate if JPA itself was doing some sort of bytecode enhancement on this object.
In order to check this out, I created a copy project, but in Java. The generated code for the User
class happens to have no bitmap$init$0
field, as follow:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="users")
public class User
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_id_seq")
@Column(name="id", updatable=false, nullable=false)
private Long id;
private String name;
private String email;
public void setId(Long id)
{
this.id = id;
时 时
public Long getId() {
return this.id;
时 时
public String getName() {
return this.name;
时 时
public void setName(String name) {
this.name = name;
时 时
public String getEmail() {
return this.email;
时 时
public void setEmail(String email) {
this.email = email;
时 时
时 时
所有这些麻烦导致我来到这个 rel=“nofollow norefererr”> post ,我非常肯定地同意。似乎将JPA与Scala Ebean/Hibertnate结合是一种真正的痛苦。我仍然不明白, Ebean 或其他东西是否将这个 bittmap$ini0
字段注入了类位元代码 。
似乎你可以试图绕过这种行为,将注解()与生成的爪哇字节码联系起来,首先为 java 编译代码,然后到 Scala 编译代码,类似于< a href=> https://stackoverflow.com/ questions/11493543/compiliting-java-annotions-with-sbt” 。但我真的不认为这很值得!