users@glassfish.java.net

problem with _at_Generatedvalue TABLE

From: <glassfish_at_javadesktop.org>
Date: Wed, 29 Aug 2007 21:25:09 PDT

I'm using netbeans, glassfish and mysql

here are my classes:

Country class:
-----------------------------------------------
[code]
@Entity
@Table(name = "country_tbl")
@NamedQueries( {
        @NamedQuery(name = "Country.findByCountryId", query = "SELECT c FROM Country c WHERE c.countryId = :countryId"),
        @NamedQuery(name = "Country.findByCountryName", query = "SELECT c FROM Country c WHERE c.countryName = :countryName")
    })
public class Country implements Serializable {

    @Id
    @SequenceGenerator(name="id_gen", sequenceName="country_gen")
    @GeneratedValue(strategy=GenerationType.TABLE , generator="id_gen")
    //_at_GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "country_id", nullable = false)
    private Integer countryId;

    @Column(name = "country_name")
    private String countryName;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "country")
    private Collection<Userinfo> userinfoCollection;
[/code]
*************************************************************
Userinfo class:
-----------------------------------------------------------
[code]
@Entity
@Table(name = "userinfo_tbl")
@NamedQueries( {
        @NamedQuery(name = "Userinfo.findByUserId", query = "SELECT u FROM Userinfo u WHERE u.userId = :userId"),
        @NamedQuery(name = "Userinfo.findByLastName", query = "SELECT u FROM Userinfo u WHERE u.lastName = :lastName"),
        @NamedQuery(name = "Userinfo.findByFirstName", query = "SELECT u FROM Userinfo u WHERE u.firstName = :firstName"),
        @NamedQuery(name = "Userinfo.findByUserName", query = "SELECT u FROM Userinfo u WHERE u.userName = :userName"),
        @NamedQuery(name = "Userinfo.findByPassword", query = "SELECT u FROM Userinfo u WHERE u.password = :password"),
        @NamedQuery(name = "Userinfo.findByStreetAddr", query = "SELECT u FROM Userinfo u WHERE u.streetAddr = :streetAddr"),
        @NamedQuery(name = "Userinfo.findByCity", query = "SELECT u FROM Userinfo u WHERE u.city = :city"),
        @NamedQuery(name = "Userinfo.findByPostalCode", query = "SELECT u FROM Userinfo u WHERE u.postalCode = :postalCode")
    })
public class Userinfo implements Serializable {

    @Id
    @SequenceGenerator(name="id_gen", sequenceName="user_gen")
    @GeneratedValue(strategy=GenerationType.TABLE , generator="id_gen")
    //_at_GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "user_id", nullable = false)
    private Long userId;

    @Column(name = "last_name", nullable = false)
    private String lastName;

    @Column(name = "first_name", nullable = false)
    private String firstName;

    @Column(name = "user_name", nullable = false)
    private String userName;

    @Column(name = "password", nullable = false)
    private String password;

    @Column(name = "street_addr")
    private String streetAddr;

    @Column(name = "city")
    private String city;

    @Column(name = "postal_code")
    private String postalCode;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userinfo")
    private Collection<Telephone> telephoneCollection;

    @JoinColumn(name = "country", referencedColumnName = "country_id")
    @ManyToOne
    private Country country;
[/code]
*************************************************
ManageUserBean
----------------------------------------------------------------
[code]
Stateless
@TransactionManagement(value=TransactionManagementType.CONTAINER)
public class ManageUserBean implements ManageUserRemote {
    @PersistenceContext(unitName="EJBModule1PU")
    private EntityManager em;
    
    //private Userinfo user;
    public void createNewUser(Userinfo user, int countryid,
                    Collection<Telephone> phones, Collection<Email> emails) throws Exception{
        if (user == null)return;
        
        Country country = new Country();
        country.setCountryName("test");
       
        user.setCountry(country);
        Collection<Userinfo> cl = new ArrayList<Userinfo>();
        cl.add(user);
        country.setUserinfoCollection(cl);
        
        em.persist(country);
    }
[/code]
**************************************************************
Test clien
--------------------------------------------------
[code]
public static void main(String[] args){
        try{
            Context ctx = new InitialContext();
            System.out.println("GOT Context!!!");
            ManageUserRemote bean = (ManageUserRemote)ctx.lookup("manageuser");
            
            Userinfo user = new Userinfo(null,"Cuong","Trinh","ctrinh","pwd");
           
            bean.createNewUser(user, 1, null, null);
            
            System.out.println("DONE!!!");
        }catch(NamingException ne){
            System.out.println(ne.toString());
        }catch(Exception e){
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }
[/code]

The table is create using:
[code]CREATE TABLE id_gen (
gen_name VARCHAR(80),
gen_val INTEGER,
CONSTRAINT pk_id_gen
PRIMARY KEY (gen_name)
);
[/code]

And the error is:
[b]javax.naming.NameNotFoundException: manageuser not found
[/b] even though I've set the jndi name in the sun-ejb-jar.xml. And if I remove the @Generatedvalue annotations, no exception was thrown but the FK is not in the database.

Also if I use @GeneratedValue(strategy=GenerationType.AUTO). The error is now:
javax.ejb.EJBException: nested exception is: java.rmi.RemoteException

What did I do wrong?hope you guys can help me out.

Thanks
[Message sent by forum member 'eviljanca' (eviljanca)]

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