Inserting the record into Database through JPA

Posted by vinay123 on Stack Overflow See other posts from Stack Overflow or by vinay123
Published on 2010-04-24T00:05:43Z Indexed on 2010/04/24 0:23 UTC
Read the original article Hit count: 477

Filed under:

In my code I am using JSF - Front end , EJB-Middile Tier and JPA connect to DB.Calling the EJB using the Webservices.Using MySQL as DAtabase. I have created the Voter table in which I need to insert the record. I ma passing the values from the JSF to EJB, it is working.I have created JPA controller class (which automatcally generates the persistence code based on the data base classes) Ex: getting the entity manager etc.,

    em = getEntityManager();
    em.getTransaction().begin();
    em.persist(voter);
    em.getTransaction().commit();

I have created the named query also:

@NamedQuery(name = "Voter.insertRecord", query = "INSERT INTO Voter v 
values v.voterID = :voterID,v.password = :password,v.partSSN = :partSSN,
v.address = :address, v.zipCode = :zipCode,v.ssn = :ssn, 
v.vFirstName = :vFirstName,v.vLastName = :vLastName,v.dob = :dob"),

But still not able to insert the record?

Can anyone help me in inserting the record into the Data base through JPA.(Persistence object)?

© Stack Overflow or respective owner

Related posts about java