*
The moose likes Object Relational Mapping and the fly likes Data Not inserting into Database JPA+Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Data Not inserting into Database JPA+Hibernate" Watch "Data Not inserting into Database JPA+Hibernate" New topic
Author

Data Not inserting into Database JPA+Hibernate

rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
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;

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;
}
}



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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


<property name="hibernate.hbm2ddl.auto" value="create"/>


This configuration option is telling Hibernate to create a new schema every time a SessionFactory is configured. If you are going to use the hbm2ddl tools you probably want this to be update.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Paul Sturrock wrote:

<property name="hibernate.hbm2ddl.auto" value="create"/>


This configuration option is telling Hibernate to create a new schema every time a SessionFactory is configured. If you are going to use the hbm2ddl tools you probably want this to be update.


Hi,

thanks for the reply, actually I have tried both the ways but no use..this is the output in JBOSS with out any errors..


t EventContext
12:38:31,193 INFO [SchemaUpdate] Running hbm2ddl schema update
12:38:31,193 INFO [SchemaUpdate] fetching database metadata
12:38:31,193 INFO [SchemaUpdate] updating schema
12:38:31,193 INFO [SchemaUpdate] schema update complete
12:38:31,193 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.fa
ctory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.p
kgs=org.jboss.namingrg.jnp.interfaces}
12:38:31,521 INFO [TomcatDeployment] deploy, ctxPath=/persistenceImpl-app
12:38:31,599 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8
080
12:38:31,615 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
12:38:31,631 INFO [ServerImpl] JBoss (Microcontainer) [5.0.1.GA (build: SVNTag=
JBoss_5_0_1_GA date=200902231221)] Started in 42s:875ms


can you please tell me whats the problem.


Thanks in Advance,
Raja.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Are you committing your transaction?
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Paul Sturrock wrote:Are you committing your transaction?


Hi,

actually I am not committing transactions..just like to save the entity class in the database..is it necessary to create an entityfactory classes?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Saving anything in a database requires a transaction.


is it necessary to create an entityfactory classes?

That depends on the context you run your application in. Is it a stand alone application or are you running it in a container?
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Paul Sturrock wrote:Saving anything in a database requires a transaction.


is it necessary to create an entityfactory classes?

That depends on the context you run your application in. Is it a stand alone application or are you running it in a container?


actually I have started a project which contains 92 tables and just to check whether JBOSS was configured perfectly or not..I have created one example entity bean class and the persistence.xml file with out any transaction classes..so what I am thinking is with out creating any additional transaction classes..when I run the JBOSS by deploying ear file .is it possible to create the new tables or not if they are not existing by checking the persistence.xml file.

sorry if the question sounds weird and please give me the answer.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


I have created one example entity bean class

Just so you know, entity beans are nothing to do with JPA, they are an EJB 2 construct that are not really used these days.

Have a read of this if you want to persist objects and you are not already using container managed transactions.
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Paul Sturrock wrote:

I have created one example entity bean class

Just so you know, entity beans are nothing to do with JPA, they are an EJB 2 construct that are not really used these days.

Have a read of this if you want to persist objects and you are not already using container managed transactions.


thanks for your help for clearing my doubt.
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Hi,

is it possible to create the tables in database using hibernate and JPA
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes. See the documentation.
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Paul Sturrock wrote:Yes. See the documentation.



Hi can you please provide any link for it..I didnt have any books for it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Not inserting into Database JPA+Hibernate
 
Similar Threads
org. postgresql. util. PSQLException: ERROR: relation does not exist
deployment error ,jpa(wl10.3.3)
How to Create Auto Schema
Connection to data source on the basis of userlogin using JPA
JPA with JSF