Results 1 to 3 of 3

Thread: Data Not inserting into Database JPA+Hibernate

Hybrid View

  1. #1

    Default Data Not inserting into Database JPA+Hibernate

    Hi All,

    I am new to JPA and Hibernate, these are my files:

    this is my Entity class

    package com.ernst.persistenceImpl.beanImpl;

    import javax.persistence.*;
    import static javax.persistence.FetchType.LAZY;
    import javax.jdo.annotations.Index;


    @Entity
    @Table(name = "ADRESSES")
    public class AdressesBeanImpl {

    @Id
    @Index(name = "ix_adress_id")
    private int adress_id;

    @Basic
    private String titel;

    @Basic
    private String vorname;

    @Basic
    private String nachnahme;

    @Basic
    private String position;

    @Basic
    private String tel;

    @Basic
    private String cell_phone;

    @Basic
    private String fax;

    @Basic
    private String email;

    @Basic
    private String website;

    @Basic(fetch = LAZY)
    @Lob
    private byte[] zusatzinfo;

    @Basic
    private String adress_strasse;

    public int getAdress_id() {
    return adress_id;
    }

    public void setAdress_id(int adress_id) {
    this.adress_id = adress_id;
    }

    public String getTitel() {
    return titel;
    }

    public void setTitel(String titel) {
    this.titel = titel;
    }

    public String getVorname() {
    return vorname;
    }

    public void setVorname(String vorname) {
    this.vorname = vorname;
    }

    public String getNachnahme() {
    return nachnahme;
    }

    public void setNachnahme(String nachnahme) {
    this.nachnahme = nachnahme;
    }

    public String getPosition() {
    return position;
    }

    public void setPosition(String position) {
    this.position = position;
    }

    public String getTel() {
    return tel;
    }

    public void setTel(String tel) {
    this.tel = tel;
    }

    public String getCell_phone() {
    return cell_phone;
    }

    public void setCell_phone(String cell_phone) {
    this.cell_phone = cell_phone;
    }

    public String getFax() {
    return fax;
    }

    public void setFax(String fax) {
    this.fax = fax;
    }

    public String getEmail() {
    return email;
    }

    public void setEmail(String email) {
    this.email = email;
    }

    public String getWebsite() {
    return website;
    }

    public void setWebsite(String website) {
    this.website = website;
    }

    public byte[] getZusatzinfo() {
    return zusatzinfo;
    }

    public void setZusatzinfo(byte[] zusatzinfo) {
    this.zusatzinfo = zusatzinfo;
    }

    public String getAdress_strasse() {
    return adress_strasse;
    }

    public void setAdress_strasse(String adress_strasse) {
    this.adress_strasse = adress_strasse;
    }

    persistence.xml file:

    <?xml version="1.0" encoding="UTF-8" ?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
    version="1.0">

    <persistence-unit name="LagerstandDS" transaction-type="JTA">

    <!-- The provider only needs to be set if you use several JPA providers
    <provider>org.hibernate.ejb.HibernatePersistence </provider> -->

    <jta-data-source>java:/LagerstandDS</jta-data-source>

    <class>com.ernst.persistenceImpl.beanImpl.Adresses BeanImpl</class>

    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1:3306/lagerstand"/>

    <property name="hibernate.connection.username" value="root"/>
    <property name="hibernate.connection.password" value="sekhar"/>

    <!-- Scan for annotated classes and Hibernate mapping XML files -->
    <property name="hibernate.archive.autodetection" value="class"/>
    <property name="hibernate.hbm2ddl.auto" value="create"/>

    <!-- SQL stdout logging -->
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="use_sql_comments" value="true"/>
    </properties>

    </persistence-unit>
    </persistence>

    I have a pom.xml which is used to build my project and it builds perfectly and when I deploy in JBOSS, its saying schema was created and schema was updated..but I didnt find any data in the database, can any one please give me some suggestion and tell me whats wrong in the files.


    Thanks in Advance,

    Regards,
    Raja.

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    Why are you using @Basic?

    its saying schema was created and schema was updated..but I didn't find any data in the database,
    Any data inserted?
    where you are calling your DAO methods to persist some data?

    or any table created?
    Can you be more explicit?

    be sure to do
    Code:
    use lagerstand;
    showtables lagerstand;
    what show?

    can any one please give me some suggestion and tell me whats wrong in the files.
    Meanwhile you don't see an error stack trace everything should be OK
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3

    Default

    Hi,

    Did you invoke any data insertion functionality after you deployed the application? Do you wrap the data access code with a transaction? If you set show_sql=true in persistence.xml, do you see any SQL inserts?
    Gabriel Axel
    Sparklix | Blog | Twitter | Github

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •