Ja, det er muligt! Nedenstående er taget fra Suns J2EE doc. Det skulle bringe dig på sporet. (Jeg har brugt det tidligere)
Generating Primary Key Values For some entity beans, the value of a primary key has a meaning for the business entity. For example, in an entity bean that represents a phone call to a support center, the primary key might include a time stamp that indicates when the call was received. But for other beans, the key's value is arbitrary--provided that it's unique. With container-managed persistence, these key values can be generated automatically by the EJB container. To take advantage of this feature, an entity bean must meet these requirements:
In the deployment descriptor, the primary key class is defined as a java.lang.Object. The primary key field is not specified.
In the home interface, the argument of the findByPrimaryKey method must be a java.lang.Object.
In the entity bean class, the return type of the ejbCreate method must be a java.lang.Object.
In these entity beans, the primary key values are in an internal field that only the EJB container can access. You cannot associate the primary key with a persistent field or any other instance variable. However, you can fetch the bean's primary key by invoking the getPrimaryKey method, and you can locate the bean by invoking its findByPrimaryKey method.
1) Ja! 2) Så unik som ordets betydning. Det er et timestamp, men hvordan det præcist er lavet det ved jeg ikke. Du kan evt. se i source-koden til Suns implementering af EJB-containeren.
Vi taler udelukkende CMP. Det er derfor EJB-containerens valg. Jeg mener at Suns RI benytter en long(Java), som jo derefter skal mappes til en DBMS-specifik datatype. Jeg går udfra, at du taler database når du nævner 'tabel'...
Selvom man bruger CMP, så er det stadig mest normalt at tabellen er oprettet i databasen i forvejen.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.