users@glassfish.java.net

Re: RE: persistence: ommiting sequence for ID?

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 May 2007 09:18:51 PDT

Thanks for Your attention Gordon.

The code is somehow typical

From bean I call
User user = new User();
 user.setLogin( login );
        user.setName( name );
        user.setPassword( password );
        user.setSurname( surname );
        user.setContactId( contact );
        user.setOfficeId( office );
        user.setChangeStamp( new Date( System.currentTimeMillis() ) );
        user.setDeleteStamp( new Date( System.currentTimeMillis() ) );
        user.setCustomId(AgencyKeyGenerator.getKey());
        user.setUserId( new BigInteger("444"));
        
        userFacade.create(user,DatabaseChoice.OfficeDatabase);

Facade: ( the databaseChoice is because of Two databases used...)

public void create(User user,DatabaseChoice databaseChoice) {
        getEntityManager(databaseChoice).persist(user);
    }

where getEntityManager gives me some EM..

and maybe the extract from configuration of Entity:

@Entity
@Table(name = "users")
@SecondaryTable(name="accounts",pkJoinColumns={_at_PrimaryKeyJoinColumn(name="user_id", referencedColumnName="user_id")})
@DiscriminatorValue("1")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="role_id", discriminatorType=DiscriminatorType.STRING)

@NamedQueries( {
        @NamedQuery(name = "User.findByUserId", query = "SELECT u FROM User u WHERE u.userId = :userId"),
        @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
        @NamedQuery(name = "User.findBySurname", query = "SELECT u FROM User u WHERE u.surname = :surname"),
        @NamedQuery(name = "User.findByChangeStamp", query = "SELECT u FROM User u WHERE u.changeStamp = :changeStamp") ,
        @NamedQuery(name = "User.findNewOrModified", query = "SELECT u FROM User u WHERE u.changeStamp BETWEEN :fromChangeStamp AND :toChangeStamp"),
        @NamedQuery(name = "User.findNotDeleted", query = "SELECT u FROM User u WHERE u.changeStamp <> :changeStamp")
    })

public class User implements Serializable {

    @Id
    @Column(name = "user_id", nullable = false)
    @SequenceGenerator(name="users_user_id_seq", sequenceName="users_user_id_seq")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="users_user_id_seq")
    private BigInteger userId;

Maybe because of this Join with secondaryTable that has no primary Key at all?


If You know why - I would really appreciate :)

Thanks in advance.

Tomek
[Message sent by forum member 'kretes' (kretes)]

http://forums.java.net/jive/thread.jspa?messageID=218756