-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA and persist(),commit
PostPosted: Sun Nov 15, 2009 5:42 pm 
Newbie

Joined: Sun Nov 15, 2009 5:31 pm
Posts: 1
Hi i am try to batch insert in JPA but i couldnt do,but i did everything that i read from books or forums.
This is reader Class
Code:
@Entity
public class Readers  implements Serializable
{
    @Id
    @GeneratedValue
    @Column(name="readerId",columnDefinition = "int(11)")
    private int id;

    @Column(name="name",columnDefinition = "varchar(255)")
    private String name;

    @Column(name="surname",columnDefinition = "varchar(255)")
    private String surname;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getSurname()
    {
        return surname;
    }

    public void setSurname(String surname)
    {
        this.surname = surname;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }
}

this is persistence.xml file
Code:
<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/persistence_1_0.xsd"
             version="1.0">
    <persistence-unit name="NewsManager" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>                                                             
             
            <property name="hibernate.archive.autodetection" value="class,hbm"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/Example?useUnicode=true"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.password" value="123123"/>
            <property name="hibernate.connection.username" value="newuser"/>

            <property name="hibernate.c3p0.min_size" value="2"/>
            <property name="hibernate.c3p0.max_size" value="7"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="3000"/>
            <property name="hibernate.connection.autocommit" value="false"/>
           
      <!--      <property name="hibernate.show_sql" value="true"/> -->
            <property name="hibernate.format_sql" value="true"/>
            <property name="use_sql_comments" value="true"/>

            <property name="dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
        </properties>
    </persistence-unit>
</persistence>

and also this id my main class
Code:
EntityManagerFactory EMF = JpaUtils.getEntityManagerFactory();
        EntityManager EM = EMF.createEntityManager();
        EM.setFlushMode(FlushModeType.COMMIT);
        EM.getTransaction().begin();



        Readers reader;
        for (int i = 1; i <= 100; i++)
        {

            try
            {
                reader = new Readers();
                reader.setName("Example:" + i);
                reader.setSurname("EExample" + i);
                EM.persist(reader);
            }
            catch (Exception ex)
            {
                System.out.println(ex.getMessage() + i);
            }
            finally
            {
                if (EM.getTransaction().isActive())
                {
                    EM.getTransaction().rollback();
                }
                else
                {
                    EM.getTransaction().begin();
                }

            }
        }
        EM.getTransaction().commit();


Now when i try to go step by step on the main class code,after each persist(),i am looking at the DB and no of records is increased by one but in batch process i must see the increase after commit() statement.i couldnt understand this trouble.

did u have any suggestion ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.