Persistence Question

Hi,
I am attempting to write something like a text game in Java. Obviously for something like this I need to be able to save the state of the program, so I am attempting to use persistence but I am running into a problem. My Game object contains everything to do with the game and I have a StartGame object that performs the saving and loading and calls game object to run.
I can successfully save and load the game object using File and Object Output/InputStreams but upon loading the Game object no longer has any of the objects it is supposed to have saved. For example, there is a currentRoom pointer that points to an object of type Room (a custom class). I want this (and many other pointers like it) to have their referenced objects saved and still be pointing to them when a file is loaded. Can anyone enlighten me as to why this is not working?
I guess the alternative might be to save each and every object within Game individually, but from what I have read it seems like it's supposed to be simpler than that. Thanks for any help.

I realized I made a silly mistake and was writing the wrong file name originally, but now I have another problem in that it will not even write the game object to the ObjectOutputStream.
This is the class that runs the game:
import java.io.*;
public class StartGame2
     static Game game;
     static boolean runOnce = true;
     public static void main(String args[])
          game = new Game();
          while(!game.exit)
               game.load = false;
               game.save = false;
               game.runGame();
               if(game.save)
                    save(game.saveName);
               if(game.load)
                    load(game.loadName);
          System.exit(0);
     static void save(String saveName)
          try
               // Create a file to write game system
               FileOutputStream out = new FileOutputStream (saveName);
               // Create an object output stream, linked to out
               ObjectOutputStream objectOut = new ObjectOutputStream (out);                    
               // Write game to disk
               objectOut.writeObject (game);               
               // Close object output stream
               objectOut.close();
               Game.print("Game saved as " + saveName);
          catch (Exception e)
               System.err.println ("Unable to create game data");
     static void load(String loadName)
          FileInputStream fin = null;
          ObjectInputStream objectIn = null;
          try
               // Create a file input stream
               fin = new FileInputStream(loadName);
               // Create an object input stream
               objectIn = new ObjectInputStream(fin);
               // Read an object in from object store, and cast it to a game
               game = (Game) objectIn.readObject();
          catch (Exception e)
               Game.print("Failed to load.");
}//End startGameThe Game class itself is of the form:
public class Game implements Serializable
        public void runGame()
          //These should only run once
          if(StartGame2.runOnce)
               welcome();          
               makeRooms();                    
               makePeople();
               if(!exit && !load)
                    intro();          
                    StartGame2.runOnce = false;
                        while(!exit && !load && !save)
                             ...doStuff...
}Edited by: DrSpock11 on Mar 2, 2009 11:06 AM

Similar Messages

  • CMP persistence questions

    Hi,
    I am using JBoss 3.0.6, CMP 2.0, default HyperSonic database.
    I wanted to know a few things
    (1) If i have to store big sized objects, what is a better idea
    -> to store on to the file system and enter the file URL's into the database OR try to store the objects into the database as BLOBS
    (2) If we start storing the objects into the filesystem I feel that there is always a risk of someone tampering the data, and i dont want the data to be visible. In such a case what can we do ?
    (3) If i choose to store these huge objects into the database ... particularly Hypersonic, what are its limitations ? How big objects can i store in it, and do i need to make any changes in any of the jboss xml files ?
    (4) I also read in some forums that storing the data into files is away from the EJB spec .. is it right ?
    Any hints or pointers to places that explain these are very much appreciated
    Regards
    Meka Toka

    my answers:
    1) I those objects are too big for HyperSonic, then the only choice is file system. If not then it depends of your performance requirements and whether you use local EJB's (with local interfaces). If you transfer large amounts of data to remote EJB's, then it may be not very fast. If it's not a big issue then use database. I would prefer database storage, if possible.
    2) You can encrypt files, or/and you can store data digests (SHA or MD5)
    in database and verify it every time you read data from files.
    3) http://hsqldb.sourceforge.net/doc/hsqlSyntax.html#Datatypes
    " In practice, objects of up to a megabyte in size have been successfully used in production databases. "
    I don't think you need to specify something special in decriptors or JBoss config files to store objects.
    "If JBossCMP cannot find a mapping for a type, it will serialize the object and use the java.lang.Object mapping."
    4) It's right. It's NOT recommened by spec. to work with files from EJB's.
    Maris Orbidans

  • CSM persistence question

    i all,
    in my balancing enviroment i need to sending multiple connection from different client to the same real server.
    there is a solution for my problem?cookie?sticky url?
    i'm very confused,it's my first configuration in this way.
    best regards
    Aghi

    Aghi,
    this is possible if there is something the CSM can use to identify the connections that have to go to the same server.
    For example, if your application can set a cookie value like server=rs1, then we can create a config based on cookie sticky to achieve what you need.
    If there is no such data to identify the server, then it doesn't seem to be possible.
    If a human can't tell us how to distinguish a connection that needs to go to server1 from another one, a machine can't do job either.
    Gilles.

  • Design Choices in a Web-only Application Using Java Persistence - Question!

    Hi,
    Is it possible to use both container and application managed entity manager factories in the same web-only application?
    It is not working for me....
    I have an application that is using container managed (injected) emf and also an application managed emf. The behavior I see is that updates from the application managed emf are not being persisted to the database but it can query properly. The container managed emf works normally.
    However, there is no error for the application managed emf. Maybe this is because I am using hypersonic in my test environment?

    Duh, forgot to joinTransaction in the app managed emf
    Edited by: edge1 on Aug 20, 2008 10:42 PM

  • EJB persistence question...

    Hi experts,
    I need to do the following operations over a table:
    1. Delete all data table.
    for example by using SQL: delete from table2. Update several rows at the same time.
    for example by using SQL: update MY_TABLE set MY_FIELD = 'New value for the column field'3. Insert several rows at the same time.
    for example by using SQL: insert into MY_TABLE select * from MY_TABLE2easiest by using SQL, but using EJBs......!!!
    I know that a EJB entity maps one row at the same time and the basic methods of the bean life cycle (create, store, remove, etc) only applies for the row mapped.
    How can I do this operations over several rows in a table using EJBs ??
    The only manner that I know is to do a loop for to iterate over each entity bean by making a findByPrimaryKey, sets bean attributes and then to wait for the ejbStore, ejbRemove, etc.
    is there another way or pattern for manage a table (several rows) in order to avoid this loop...?
    thanks in advance

    I know that a EJB entity maps one row at the same
    time and the basic methods of the bean life cycle
    (create, store, remove, etc) only applies for the row
    mapped.Exactly !
    How can I do this operations over several rows in a
    table using EJBs ?? It's not possible.
    The only manner that I know is to do a loop for to
    iterate over each entity bean by making a
    findByPrimaryKey, sets bean attributes and then to
    wait for the ejbStore, ejbRemove, etc.
    is there another way or pattern for manage a table
    (several rows) in order to avoid this loop...?No. Therefore I would advice to use SQL for those operations.
    EJB's won't work well, because of performance problems.

  • Noob Question: Problem with Persistence in First Entity Bean

    Hey folks,
    I have started with EJB3 just recently. After reading several books on the topic I finally started programming myself. I wanted to develop a little application for getting a feeling of the technology. So what I did is to create a AppClient, which calls a Stateless Session Bean. This Stateless Bean then adds an Entity to the Database. For doing this I use Netbeans 6.5 and the integrated glassfish. The problem I am facing is, that the mapping somehow doesnt work, but I have no clue why it doesn't work. I just get an EJBException.
    I would be very thankfull if you guys could help me out of this. And don't forget this is my first ejb project - i might need a very detailed answer ... I know - noobs can be a real ....
    So here is the code of the application. I have a few methods to do some extra work there, you can ignore them, there are of no use at the moment. All that is really implemented is testConnection() and testAddCompany(). The testconnection() Methode works pretty fine, but when it comes to the testAddCompany I get into problems.
    Edit:As I found out just now, there is the possibility of Netbeans to add a Facade pattern to an Entity bean. If I use this, everythings fine and it works out to be perfect, however I am still curious, why the approach without the given classes by netbeans it doesn't work.
    public class Main {
        private EntryRemote entryPoint = null;
        public static void main(String[] args) throws NamingException {
            Main main = new Main();
            main.runApplication();
        private void runApplication()throws NamingException{
            this.getContext();
            this.testConnection();
            this.testAddCompany();
            this.testAddShipmentAddress(1);
            this.testAddBillingAddress(1);
            this.testAddEmployee(1);
            this.addBankAccount(1);
        private void getContext() throws NamingException{
            InitialContext ctx = new InitialContext();
            this.entryPoint = (EntryRemote) ctx.lookup("Entry#ejb.EntryRemote");
        private void testConnection()
            System.err.println("Can Bean Entry be reached: " + entryPoint.isAlive());
        private void testAddCompany(){
            Company company = new Company();
            company.setName("JavaFreaks");
            entryPoint.addCompany(company);
            System.err.println("JavaFreaks has been placed in the db");
        }Here is the Stateless Session Bean. I added the PersistenceContext, and its also mapped in the persistence.xml file, however here the trouble starts.
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless(mappedName="Entry")
    public class EntryBean implements EntryRemote {
        @PersistenceContext(unitName="PersistenceUnit") private EntityManager manager;
        public boolean isAlive() {
            return true;
        public boolean addCompany(Company company) {
            manager.persist(company);
            return true;
        public boolean addShipmentAddress(long companyId) {
            return false;
        public boolean addBillingAddress(long companyId) {
            return false;
        public boolean addEmployee(long companyId) {
            return false;
        public boolean addBankAccount(long companyId) {
            return false;
    }That you guys and gals will have a complete overview of whats really going on, here is the Entity as well.
    package ejb;
    import java.io.Serializable;
    import javax.persistence.*;
    @Entity
    @Table(name="COMPANY")
    public class Company implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        @Column(name="COMPANY_NAME")
        private String name;
        public Long getId() {
            return id;
        public void setId(Long id) {
            this.id = id;
       public String getName() {
            return name;
        public void setName(String name) {
            this.name = name;
            System.err.println("SUCCESS:  CompanyName SET");
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Company)) {
                return false;
            Company other = (Company) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            return true;
        @Override
        public String toString() {
            return "ejb.Company[id=" + id + "]";
    }And the persistence.xml file
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
      <persistence-unit name="PersistenceUnit" transaction-type="JTA">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <jta-data-source>jdbc/sample</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
          <property name="toplink.ddl-generation" value="create-tables"/>
        </properties>
      </persistence-unit>
    </persistence>And this is the error message
    08.06.2009 10:30:46 com.sun.enterprise.appclient.MainWithModuleSupport <init>
    WARNUNG: ACC003: Ausnahmefehler bei Anwendung.
    javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.RemoteException: Transaction aborted; nested exception is: javax.transaction.RollbackException: Transaktion für Zurücksetzung markiert.; nested exception is:
            javax.transaction.RollbackException: Transaktion für Zurücksetzung markiert.
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.RemoteException: Transaction aborted; nested exception is: javax.transaction.RollbackException: Transaktion für Zurücksetzung markiert.; nested exception is:
            javax.transaction.RollbackException: Transaktion für Zurücksetzung markiert.
            at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:243)
            at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:205)
            at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
            at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
            at ejb.__EntryRemote_Remote_DynamicStub.addCompany(ejb/__EntryRemote_Remote_DynamicStub.java)I spend half the night figuring out whats wrong, however I couldnt find any solution.
    If you have any idea pls let me know
    Best regards and happy coding
    Taggert
    Edited by: Taggert_77 on Jun 8, 2009 2:27 PM

    Well I don't understand this. If Netbeans created a Stateless Session Bean as a facade then it works -and it is implemented as a CMP, not as a BMP as you suggested.
    I defenitely will try you suggestion, just for curiosity and to learn the technology, however I dont have see why BMP will work and CMP won't.
    I also don't see why a stateless bean can not be a CMP. As far as I read it should not matter. Also on the link you sent me, I can't see anything related to that.
    Maybe you can help me answering these questions.
    I hope the above lines don't sound harsh. I really appreciate your input.
    Best regards
    Taggert

  • Newbie question on Java Persistence API - Entity Beans

    Hi All,
    I am basically new to Entities and the Java Persistence API. My question is, when using a container managed EntityManager, do I have to manually tidy-up any resources? Say for example, do I have to explicitly close the database connection (if ever I have that ability)? Invoke close() on EntityManager?
    - Pat

    You don't have to. That's what they mean by container managed. The container does it for you.
    In fact you will get an IllegalStateException if you call close on a container-managed EntityManager.

  • Persistence API newbie question

    Hello everybody!
    I am new at J2EE development, so can you explain me some details. We're curently do J2EE application at work and using J2EE 1.5 features(EJB 3.0, Persistence etc..). I don't understand exactly what lies under annotations. Let's take Persistence API. All anotations and classes is in javax.persistence package. What is that package, where it come from? Is it located in container or where? In fact I would like to use Persistence API on sites managed by Apache Tomcat Server. Is it possible, what classes do I need? Another question is it is possible to use that API at Swing Applications, and what do I need to do this.
    Please, explain me little of where all that stuff come from.
    Thank you!

    anotations and classes is in javax.persistence
    package. What is that package, where it come from? Is
    it located in container or where? Java Persistence API (JPA) is part of JavaEE 5 platform, and so is available in all JavaEE 5 compliant application servers. In JavaEE SDK 5, these classes are in lib/javaee.jar. JPA is also available as a standalone technology. There are several products that are implementing this technology, like Hibernate, TopLink, or OpenJPA.
    The specification:
    http://jcp.org/en/jsr/detail?id=220
    Persistence Part in JavaEE 5 Tutorial (Part Four: Persistence )
    http://java.sun.com/javaee/5/docs/tutorial/doc/
    In fact I would
    like to use Persistence API on sites managed by
    Apache Tomcat Server. Is it possible, what classes do
    I need? Another question is it is possible to use
    that API at Swing Applications, and what do I need to
    do this. They are all possible ways of using JPA. See JavaEE 5 Tutorial for more details. The newly released NetBeans 5.5 has nice support for developing and deploying JPA applications. NetBeans site has a lot of resources on this topic. For example:
    http://www.netbeans.org/kb/55/persistence_ontomcat.html
    http://www.netbeans.org/kb/articles/hibernate-javaee.html
    -cheng

  • Question: Will non committed persistence data loss if my application which is using Kodo/JDO crashes???

    Hi,
    I am very new to JDO and Kodo and I am still learning. I have a user
    specification that requires no data loss when the application crashes. If I
    am developing my application using Kodo for data access layer, when my
    application crashes just because and needs to restart, what happen to all
    the persistence data that have not committed to database??
    Vivian

    I am very new to JDO and Kodo and I am still learning. I have a user
    specification that requires no data loss when the application crashes.
    If I am developing my application using Kodo for data access layer, when
    my application crashes just because and needs to restart, what happen to
    all the persistence data that have not committed to database??If an app crashes, all current transactions will be aborted. There is a
    difference between data loss and aborting the current transaction. Data
    loss implies losing some persistent data -- data that resides in the
    database. That won't happen with Kodo.
    You will, however, lose any changes that have not been committed to the
    database yet. This is a good thing. You absolutely DO NOT want an
    unfinished transaction to be recorded, because that could violate the
    integrity of your data. Consider a transaction that decrements from one
    bank account and increments another to implement a funds transfer. You
    certainly wouldn't want to record the decrement unless you are absolutely
    sure the increment would be recorded too!

  • Question on Persistence (Entity Beans, Hibernate, JDBC)

    Hi everybody!
    Until now, I have read a lot about persistence in the J2EE-sector, but I am still confused about which technology to used in my case.
    I hope, that maybe you can give me some hints, by telling me which technology is good or bad regarding my requirements:
    I want to build a customer- and order-management system fullfilling the following requirements:
    1. The client is a Java application, the server is a JBOSS 4.0.1
    2. The databasa scheme exists already and I'm not allowed to change it.
    Some data, that logically belongs together and which shall be presented together to the client is distributed over 2 database tables.
    3. The user cannot just create new and view data, but will also edit existing data quite often.
    4. The user can assign products to an order. Often, there will be more than 1000 products assigned to an order, which will be presented to the user as a table (e.g. JTable). The user can then edit each cell of that 1000-row table, which of course will lead to an update in the db.
    5. The user can also assign customers to a specific role in an order-process. On the other hand, each customer can make many orders.
    So, we have a n:m relation here with the db-tables Customer, Order, OrderCustomer.
    6. A complex search functionality has to be implemented, where the db-query is created dynamically at runtime.
    7. The application is a multi-user application (about 10 users). It will be very rare, that users will work on the same data at the same time, but it might happen.
    8. The database type (SAP DB) will not be changed in the near future.
    With these 8 requirements in mind, I dealed a lot with EntityBeans, Hibernate and JDBC with SesseionBeans during the last 2 weeks.
    Until now, I came to the following conclusions.
    Hibernate is too slow. That'S bad, for data is edited very often and sometimes I want to edit just a single cell in 1000-row table.
    Hibernate's biggest advantage - that it makes your application independent of the database type - is not even required (see point 8).
    JDBC with SessioBeans: Very fast (I tried a simple query and it was about 10 times faster than Hibernate).
    The disadvantage is, that I have to take care about all the transaction, concurrency control etc. things.
    If I use JDBC, I want to do it that way: A SessionFacade accesses a DAO-object which executes the DB-query and returns the result to the SessionFacade which in the last step will pass the result to the client.
    Entity Beans: I am completely confused with Entity Beans.
    I read a lot about the CompositeEntity-Pattern for BMP. But on sun's J2EE Pattern page (http://java.sun.com/blueprints/corej2eepatterns/Patterns/CompositeEntity.html)
    they said, that it's just useful when using the EJB 1.1 specification, because from EJB 2.0. the container or whatever will take care about lazy loading and store optimization.
    So, from EJB 2.0. you should prefer using CMP-Beans with Container Managed Relationships (CMR), but as I heard, the dependent objects cannot be accessed and changed by the client when using CMPBeans with CMR.
    However, a simple DB/Entity-mapping will not work in my case, because as mentioned above, there are thousands of products from the db to be managed at the same time. So here, I thought, the Composite pattern with its lazy loading strategy would be useful.
    Furthermore, I have an n:m relationship in my database scheme, which is not trivial to map to entity beans. And don't forget that some related data is spread over 2 databse tables.
    To sum it up, it would be very nice if some of you could clarify this perisistence nightmare, especially some clarification about if and how to use EntityBeans when having n:m relationships, editing data a lot, managing lots of table rows at once and having related data distributed over 2 database tables.
    So, which technology would you prefer with the 8 requirements in mind? Hibernate, Entity Beans or JDBC with SessionBeans? Or would you prefer a mixed solution?
    Thanx for every hint.
    Regards,
    egon

    Here the requested information about the test:
    Goal:
    Find all customers, who's branches have the String "Branch" in their name.
    Both times, a simple client accesses the same SessionBean in a JBOSS-Container.
    This Bean has 2 methods. One accesses the DB via Hibernate (executeCriteria), the other one via JDBC (executeCriteriaJDBC).
    The code to count the seconds of computation is as follows:
    long startTime = System.currentTimeMillis();
    List customerList = bean.executeCriteria(dc);
    System.out.println("Hibernate: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    startTime = System.currentTimeMillis();
    List customerListJDBC = bean.executeCriteriaJDBC(query);
    System.out.println("JDBC: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    HIBERNATE:
    CODE:
    Branch Branch = new Branch();
    Branch.setName("%Branch%");
    Example example = Example.create(Branch);     
    DetachedCriteria dc = DetachedCriteria.forClass(Customer.class)
    .createCriteria("branches").add(example.enableLike()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    QUERY:
    select
            this_.UUID as UUID1_1_,
            this_.NAME as NAME1_1_,
            this_.CUSTOMERNO as CUSTOMERNO1_1_,
            this_.SHORTDESC as SHORTDESC1_1_,
            this_.LONGDESC as LONGDESC1_1_,
            this_.TAXNUMBER as TAXNUMBER1_1_,
            this_.SALESTAXID as SALESTAXID1_1_,
            this_.ACCOUNTHOLDER as ACCOUNTH8_1_1_,
            this_.BANKACCOUNT as BANKACCO9_1_1_,
            this_.BANKCODE as BANKCODE1_1_,
            this_.BANKNAME as BANKNAME1_1_,
            this_.AREA1TEXT as AREA12_1_1_,
            this_.AREA2TEXT as AREA13_1_1_,
            this_.AREA3TEXT as AREA14_1_1_,
            this_.AREA4TEXT as AREA15_1_1_,
            this_.AREA5TEXT as AREA16_1_1_,
            this_.CH_UUID as CH17_1_1_,
            this_.REFTEXT1 as REFTEXT18_1_1_,
            this_.REFTEXT2 as REFTEXT19_1_1_,
            this_.REFTEXT3 as REFTEXT20_1_1_,
            branch1_.UUID as UUID0_0_,
            branch1_.NAME as NAME0_0_,
            branch1_.ILN as ILN0_0_,
            branch1_.BRANCHID as BRANCHID0_0_,
            branch1_.SHORTDESC as SHORTDESC0_0_,
            branch1_.LONGDESC as LONGDESC0_0_,
            branch1_.BAGSRECEIVED as BAGSRECE7_0_0_,
            branch1_.CUSTOMER_UUID as CUSTOMER8_0_0_
        from
            CUSTOMER this_,
            BRANCH branch1_
        where
            this_.UUID=branch1_.CUSTOMER_UUID
            and (
                branch1_.NAME like ?
    RESULT:
    Customername: Customer_A
    Customername: Customer_F
    Customername: Customer_D
    Customername: Customer_R
    Customername: Customer_S
    TIME:
    Hibernate: 1.343 sek
    JDBC:
    QUERY:
    Select distinct c.* from Customer c, Branch b where b.id=b.Customer_id and b.name like '%Branch%'
    // After getting the result of the query: Create a list of Customer-objects. Set all attributes of each Customer-object.
    RESULT:
    Customername: Customer_R
    Customername: Customer_A
    Customername: Customer_S
    Customername: Customer_D
    Customername: Customer_F
    TIME:
    JDBC: 0.125 sek
    The Customer.hbm.xml (auto-generated in Eclipse with Middlegen)
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    <hibernate-mapping>
    <!--
        Created by the Middlegen Hibernate plugin 2.2
        http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    -->
    <class
        name="hibernate.hibernate.Customer"
        table="CUSTOMER"
        lazy="false"
    >
        <id
            name="uuid"
            type="java.lang.String"
            column="UUID"
        >
            <generator class="assigned" />
        </id>
        <property
            name="name"
            type="java.lang.String"
            column="NAME"
            length="100"
        />
        <property
            name="customerno"
            type="java.lang.Integer"
            column="CUSTOMERNO"
            length="5"
        />
        <property
            name="shortdesc"
            type="java.lang.String"
            column="SHORTDESC"
            length="50"
        />
        <property
            name="longdesc"
            type="java.lang.String"
            column="LONGDESC"
            length="100"
        />
        <property
            name="taxnumber"
            type="java.lang.String"
            column="TAXNUMBER"
            length="50"
        />
        <property
            name="salestaxid"
            type="java.lang.String"
            column="SALESTAXID"
            length="50"
        />
        <property
            name="accountholder"
            type="java.lang.String"
            column="ACCOUNTHOLDER"
            length="50"
        />
        <property
            name="bankaccount"
            type="java.lang.String"
            column="BANKACCOUNT"
            length="50"
        />
        <property
            name="bankcode"
            type="java.lang.String"
            column="BANKCODE"
            length="50"
        />
        <property
            name="bankname"
            type="java.lang.String"
            column="BANKNAME"
            length="50"
        />
        <property
            name="area1text"
            type="java.lang.String"
            column="AREA1TEXT"
            length="50"
        />
        <property
            name="area2text"
            type="java.lang.String"
            column="AREA2TEXT"
            length="50"
        />
        <property
            name="area3text"
            type="java.lang.String"
            column="AREA3TEXT"
            length="50"
        />
        <property
            name="area4text"
            type="java.lang.String"
            column="AREA4TEXT"
            length="50"
        />
        <property
            name="area5text"
            type="java.lang.String"
            column="AREA5TEXT"
            length="50"
        />
        <property
            name="chUuid"
            type="java.lang.String"
            column="CH_UUID"
            length="50"
        />
        <property
            name="reftext1"
            type="java.lang.String"
            column="REFTEXT1"
            length="50"
        />
        <property
            name="reftext2"
            type="java.lang.String"
            column="REFTEXT2"
            length="50"
        />
        <property
            name="reftext3"
            type="java.lang.String"
            column="REFTEXT3"
            length="50"
        />
        <!-- Associations -->
        <!-- bi-directional one-to-many association to Branch -->
        <set
            name="branches"
            lazy="true"
            inverse="true"
           cascade="all"
        >
            <key>
                <column name="CUSTOMER_UUID" />
            </key>
            <one-to-many
                class="hibernate.hibernate.Branch"
            />
        </set>
    </class>
    </hibernate-mapping>So, seems to me like Hibernate is also getting the data from the Branch-Table related to each Customer. Maybe this is the reason, why Hibernate is slower.
    But as you can see in the mapping-File of the customer, I wanted Branches to be lazy loaded.
    Do you have any ideas, why Hibernate is so much slower? Any hints for optimizing that code?
    Do you have any further tricks to optimize Hibernate? Unfortunately I am not allowed to make changes at the database, so I cannot e.g. set indices for optimization.
    However, I�m a Hibernate-Newbie. In fact, I just made this test and was very disappointed about its result, so I didn�t keep on working with Hibernate.
    But maybe you can proof me, that Hibernate is a good choice. If so, do you have any good resources (links, books) that help working with Hibernate in connection with JBOSS, describe how to map n:m relationships, show how to work with large results and so forth?
    Thanx for help,
    egon

  • Question on Using Persistence Object

    Hi,
    I want to store a hashtable of persistent info with about five attributes (id, name, username, date) in order to not always call the database. I am either going to use session or request objects.
    My question is if it's a good idea to store the hashtable with 2000 records just to avoid the database connection or should I just stick with using database connection using connection pooling? Thanks.
    Mkie

    How long you are going to store it ????
    1. If it is for a long time then this is not a good strategy as:
    a) Database data can change (in that case you will have wrong data)
    b) Your heap memory will be unnecessarily loaded.
    2. If it is for a very short time then it again carries no meaning as creating the object will have a significant overhead.
    3) If it is something between these two. You need to have a thorough analysis to see which would be best. However in my humble opinion a scrollable resultset(JDBC 2.0) will still be better.
    Shubhrajit

  • Question about Java Persistence API.

    is Java Persistence API a Object-Relational Mapping Framework, or the java Programmer can use this API to do mapping between Java Applicatiion and Relational Database ??

    http://java.sun.com/javaee/overview/faq/persistence.jsp

  • Question about persistence.xml

    Hi,
    I have two persistence units in one persistence.xml file. When I deploy my ejb3 file, my Car entity bean (@Entity) creates two tables in the database (one for each persistence-unit). I want the table created in only one persistence-unit. How I tell to the entity bean what persistence-unit it has to use and what it has not?
    Thanks
    Luiz Carlos

    Ok,
    I find a way.
    All I have to do was put the property
    <property name="hibernate.archive.autodetection" value="false"/>
    in the persistence.xml and define the classes I wanna to use with
    <class>SomeClass</class>
    <class>AnotherClass</class>
    It was too much work but was the only way I found..
    Thanks anyway
    Luiz Carlos

  • Question on persistence

    I would like to know if using JPA/hibernate would be better than simple JDBC?
    The reason why I am asking is, Hibernate would have the caching/pooling..
    Where as JDBC its plain connection ....
    I would like to know your inputs
    thanks

    Yes, you'll find it a lot easier to use a higher-level persistence API than to use JDBC directly.
    The persistence runtime can also give you much better performance because it
    knows more about what your application is trying to do. Finally, using a higher-level
    persistence API isolates your code from using native SQL.
    Now that the Java Persistence API is available I would recommend it over Hibernate. Most of
    the functionality from Hibernate has been incorporated into the standard. Writing to that
    API will give you more flexibility in choosing different persistence implementations should you
    need to do that in the future.
    You can find more information on the Java Persistence API in the Java EE 5 tutorial :
    http://java.sun.com/javaee/5/docs/tutorial/doc/
    And here's the home page for the Persistence implementation in the Java EE 5 SDK :
    https://glassfish.dev.java.net/javaee5/persistence/
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • General Persistence Implementation Strategy Question

    Hi,
    I want to implement a J2EE application and use a persistence system like Hibernate. I will have to create several beans and set-up my ORM properly. Now, if I create an Enterprise project in NetBeans, where should I put my Peristence code? In a Web container or in a EBJ container knowing that both JSP pages and EJB will refer to my persisted beans? Or should I create another separate project and include the corresponding .jar in both my Web or EJB containers?
    What is the best strategy?
    Thanks,
    J.

    Jrm wrote:
    Hi,
    I want to implement a J2EE application and use a persistence system like Hibernate. I will have to create several beans and set-up my ORM properly. Now, if I create an Enterprise project in NetBeans, where should I put my Peristence code? In a Web container or in a EBJ container +
    knowing that both JSP pages and EJB will refer to my persisted beans+? I would say that JSPs should not be contacting your database directly. Better to go through a well-defined service layer that hides the persistence layer. All security, binding, and validation issues should be resolved before the service layer is called.
    Or should I create another separate project and include the corresponding .jar in both my Web or EJB containers?Both? Wrong.
    %

Maybe you are looking for