×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Here you go...

Whether you use single-fielded or multi-fielded primary key id determined by your business data.

Wrapper classes (Integer, Boolean...) cannot be used as primary key because their sole instance variable is PRIVATE. (Wrapper classes follow the immutable pattern.) The instance variables of a primary key must be PUBLIC so that the EJB container can access them directly.
To say, you have a primary class as follows:

public class PK implements java.io.Serializable{

public PK(id) {
this.id=id;
}
public int id;
}

You should be abale to write the following code:

PK pk= new PK(4);
pk.id=123;

Note the syntax above that directly accesses id.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / EJB. What's the difference between compound primary key and single-field key? Why cannot the primary keys be primitive types in single-field key? I read some books but can't get the answer. thank you!
    • Here you go...
      Whether you use single-fielded or multi-fielded primary key id determined by your business data.

      Wrapper classes (Integer, Boolean...) cannot be used as primary key because their sole instance variable is PRIVATE. (Wrapper classes follow the immutable pattern.) The instance variables of a primary key must be PUBLIC so that the EJB container can access them directly.
      To say, you have a primary class as follows:

      public class PK implements java.io.Serializable{

      public PK(id) {
      this.id=id;
      }
      public int id;
      }

      You should be abale to write the following code:

      PK pk= new PK(4);
      pk.id=123;

      Note the syntax above that directly accesses id.