Hi all, hi Gus,

after hours of trial and error I found a solution for my problem.
It was neither the jdo, nor the repository. It was my application source
code. For some reason, the line

Collection all = (Collection)query.execute();

caused the described error.
I changed the tutorial5-application to operate with my userclass and
corresponding jdo's, and it's working. I really don't know what the problem
is with my old application. If someone knows, I'm extremely interested in
the explanation.

Special thanks to Gus and Thomas,
merry christmas to everybody.


Here is the old (error-causing) source code:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
FILE: Frontend.java

package dbsii;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Vector;
import java.util.Collection;

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Transaction;
import javax.jdo.Query;

import org.apache.ojb.broker.util.ui.AsciiSplash;
import org.apache.ojb.jdori.sql.OjbStorePMF;
import org.apache.ojb.broker.PersistenceBrokerFactory;

public class Frontend {

        private PersistenceManagerFactory factory;
        private PersistenceManager manager;

        public Frontend() {

                // create PersistenceManagerFactory
              try {
                        factory = new OjbStorePMF();
              } catch (Throwable t) {
                        System.out.println("ERROR: " + t.getMessage());
                t.printStackTrace();
              }

              manager = null;

        }


        public static void main(String[] args) {

                Frontend frontend = new Frontend();
                frontend.run();

        }

        private void run() {

        System.out.println(AsciiSplash.getSplashArt());
        System.out.println("Welcome to the DBSII Ferienhaus Frontend");
        System.out.println();

                int command;

                do {
                        String[] mainmenu = new String[4];
                        mainmenu[0] = "Insert a new house";
                        mainmenu[1] = "Get all listings for one house";
                        mainmenu[2] = "Get all houses";
                        mainmenu[3] = "Exit";

                        displaySelection(mainmenu);
                        System.out.println("type in number to select");
                        command = Integer.parseInt(readLine());

                        switch(command) {
                                case 1 :
                                                        insertHouse();
                                                        break;
                                case 2 :
                                                        getHouseListings();
                                                        break;
                                case 3 :
                                                        getHouses();
                                                        break;
                        }

                } while(command < 4);

                System.out.println("\nbye\n");

        }

    private String readLine() {

        try {
            BufferedReader rin = new BufferedReader(new
InputStreamReader(System.in));
            return rin.readLine();
        } catch (Exception e) {
            return "";
        }

    }

    private void displaySelection(String[] selection) {

                System.out.println();

        for (int i = 0; i < selection.length; i++)
                System.out.println("[" + (i+1) + "] " + selection[i]);

    }

    private void insertHouse() {

                // Create new House
                House newhouse = new House();

                System.out.print("Insert ID: ");
                newhouse.setId((int) Integer.parseInt(readLine()));

                System.out.print("Insert house name: ");
                newhouse.setName((String) readLine());

                System.out.println("New house " + newhouse.getName() + " for owner " +
newhouse.getId());

                // now perform persistence operations
        manager = factory.getPersistenceManager();

                Transaction tx = null;
                tx = manager.currentTransaction();
                tx.begin();

                manager.makePersistent(newhouse);

                // 5. commit transaction
                tx.commit();

                manager.close();

        }

        private void getHouseListings() {

                manager = factory.getPersistenceManager();

                try {

                // JDO does not like old instances...

PersistenceBrokerFactory.defaultPersistenceBroker().clearCache();

                manager.currentTransaction().begin();
                Query query = manager.newQuery(House.class);

                Collection all = (Collection)query.execute();

                // now iterate over the result to print each product
                java.util.Iterator iter = all.iterator();
                if (! iter.hasNext()) {
                                System.out.println("No Product entries found!");
                }

                        while (iter.hasNext()) {
                        House house = (House) iter.next();
                        System.out.println(house.toString());
            }

            manager.currentTransaction().commit();

                } catch (Throwable t) {
                t.printStackTrace();
                }

                finally {
                manager.close();
                }
        }

        private void getHouses() {

                System.out.print("Insert house - ID: ");
                int house = Integer.parseInt(readLine());
                System.out.println("All listings for house " + house);

        }

}

-----Ursprüngliche Nachricht-----
Von: Gus Heck [mailto:[EMAIL PROTECTED]
Gesendet: Sonntag, 21. Dezember 2003 17:17
An: OJB Users List
Betreff: Re: AW: AW: AW: JDO - Unable to build object instance


Sebastian,

One thing I notice that is different about your implementation (from
mine) is that your table name does not directly match your class name. I
think that _shouldn't_ matter, but it is a difference. There are few
other differences too.

I notice your jdo file is full of ojb-extensions to specify table names,
user name and such. This also differs from mine.  Mine looks like this
(one class only shown, generated by Xdoclet)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects
Metadata 1.0//EN" "http://java.sun.com/dtd/jdo_1_0.dtd";>

<jdo>
  <package name="org.cs101.fdb.impl.jdo">
    <class name="LocationBase"
           identity-type="application"
    > <!-- end class tag -->
    </class>
  </package>

    <!--
    To use additional vendor extensions, create a vendor-extensions.xml
file that
    contains the additional extensions (in extension tags) and place it
in your
    projects merge dir.
    -->

</jdo>

What is working for me is Xdoclet generated repository_user.xml, Xdoclet
generated package.jdo, and MySQL. Torque is creating the database tables
for me at runtime, though creating the tables at build time or
independantly should suffice so long as nothing silly happens like
creating tables in one db and then connecting to another. Insert usual
caveats about everything staying in sync here...

One direction you might take is to cut back to letting everything fall
into default naming and see if it works, then if it does, add in your
customizations one by one to see what breaks it.

Looking at your extension elements, I also just wondered this... did you
specify your user name and password in repository.xml
(repository_database.xml)? Granted the error message is very odd if that
is the type of problem here, but...

-Gus

Sebastian Muench wrote:

>Hi,
>
>at first, thank you for help so far. Unfortunately, the error message is
>still appearing. I checked the information given by the doc you referred me
>to, Gus. The strange thing at all is, that I can make new objects
persistent
>without problems. But retrieving collections is still the problem. I
checked
>and doublechecked everything, but don't know where's the problem.
>
>My persistente class is House. I'm testing on the HSQLDB, comming with OJB.
>I prepare my user class for enhancing by compiling it as usual, and copy
the
>class files to my dir target/classes/"<package>"/ and
>target/classestest/"<package>"/
>As I already wrote, enhancing is successful.
>
>Here some important lines from my repository_jdo.xml, House.jdo,
House.java,
>etc.
>
>
>SQL statement for the table in HSQLDB
>
>CREATE TABLE Seb_House (
>ID INTEGER NOT NULL PRIMARY KEY,
>NAME VARCHAR)
>
>
>
>
>Corresponding mapping tags in repository_jdo.xml
>
>   <!-- Definitions for dbsii.House -->
>   <class-descriptor
>          class="dbsii.House"
>          table="Seb_House"
>   >
>      <field-descriptor
>         name="id"
>         column="ID"
>         jdbc-type="INTEGER"
>         primarykey="true"
>      />
>      <field-descriptor
>         name="name"
>         column="NAME"
>         jdbc-type="VARCHAR"
>      />
>   </class-descriptor>
>
>
>
>The persistente class file
>
>package dbsii;
>
>import java.io.Serializable;
>
>class House implements Serializable {
>
>       private int id;
>       protected String name;
>
>       public House() {
>       }
>
>       public House(int id, String name) {
>               this.id = id;
>               this.name = name;
>       }
>
>       public int getId() {
>               return this.id;
>       }
>
>       public String getName() {
>               return this.name;
>       }
>
>       public void setId(int id) {
>               this.id = id;
>       }
>
>       public void setName(String name) {
>               this.name = name;
>       }
>
>       public String toString() {
>                return "[" + this.id + "] " + this.name;
>        }
>
>}
>
>
>
>
>The corresponding House.jdo
>
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE jdo PUBLIC "-//Sun Microsystems, Inc.//DTD Java Data Objects
>Metadata 1.0//EN" "http://java.sun.com/dtd/jdo_1_0.dtd";>
>
><jdo>
>
> <!--extension vendor-name="ojb" key="dbplatform" value="hsqldb"/>
> <extension vendor-name="ojb" key="dbjdbc-level" value="2.0"/>
> <extension vendor-name="ojb" key="dbdriver"
value="org.hsqldb.jdbcDriver"/>
> <extension vendor-name="ojb" key="dbprotocol" value="jdbc"/>
> <extension vendor-name="ojb" key="dbsubprotocol" value="hsqldb"/>
> <extension vendor-name="ojb" key="dbalias" value="../OJB"/>
> <extension vendor-name="ojb" key="dbusername" value="sa"/>
> <extension vendor-name="ojb" key="dbpassword" value=""/-->
>
> <package name="dbsii">
>
>  <class name="House">
>  <extension vendor-name="ojb" key="table" value="Seb_House"/>
>
>  <field name="id">
>    <extension vendor-name="ojb" key="column" value="ID"/>
>   </field>
>   <field name="name">
>    <extension vendor-name="ojb" key="column" value="NAME"/>
>   </field>
>  </class>
> </package>
></jdo>
>
>
>
>The lines causing the error
>(pretty the same as in the jdo tutorial)
>
>manager = factory.getPersistenceManager();
>
>try {
>
>       // JDO does not like old instances...
>       PersistenceBrokerFactory.defaultPersistenceBroker().clearCache();
>
>       manager.currentTransaction().begin();
>       Query query = manager.newQuery(House.class);
>
>// >>> NEXT LINE CAUSES THE ERROR <<<
>       Collection all = (Collection)query.execute();
>
>       // now iterate over the result to print each product
>       java.util.Iterator iter = all.iterator();
>       if (! iter.hasNext()) {
>               System.out.println("No Product entries found!");
>       }
>
>       while (iter.hasNext()) {
>               House house = (House) iter.next();
>               System.out.println(house.toString());
>       }
>
>}
>
>...
>
>
>
>
>The error message
>
>[JDO] DEBUG: OjbStoreConnector.begin: connectionReadyForRelease=false
>org.apache.ojb.broker.PersistenceBrokerException: Unable to build object
>instance (MAYBE you don't have a constructor available):class dbsii.House
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithReflection(
R
>owReaderDefaultImpl.java:239)
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectFrom(RowRe
a
>derDefaultImpl.java:115)        at
>org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsItera
t
>or.java:428)
>        at
>org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:256)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:147)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:244)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:263)
>        at
>org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persi
s
>tenceBrokerImpl.java:998)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at org.apache.ojb.jdori.sql.OjbExtent.<init>(OjbExtent.java:98)
>        at
>org.apache.ojb.jdori.sql.OjbStoreManager.getExtent(OjbStoreManager.java:251
)
>        at com.sun.jdori.common.PersistenceManagerImpl.getExtent(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.checkCandidates(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.execute(Unknown Source)
>        at dbsii.Frontend.getHouseListings(Frontend.java:148)
>        at dbsii.Frontend.run(Frontend.java:68)
>        at dbsii.Frontend.main(Frontend.java:40)
>Caused by:
>org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: (Could
>not instantiate dbsii.House: Class
>org.apache.ojb.broker.util.ConstructorHelper can not access a member of
>class dbsii.House with modifiers "public")
>        at
>org.apache.ojb.broker.util.ConstructorHelper.instantiate(ConstructorHelper.
j
>ava:162)
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithReflection(
R
>owReaderDefaultImpl.java:235)
>        ... 17 more
>Caused by: java.lang.IllegalAccessException: Class
>org.apache.ojb.broker.util.ConstructorHelper can not access
>a member of class dbsii.House with modifiers "public"
>        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
>        at java.lang.reflect.Constructor.newInstance(Constructor.java:268)
>        at
>org.apache.ojb.broker.util.ConstructorHelper.instantiate(ConstructorHelper.
j
>ava:158)
>        ... 18 more
>[org.apache.ojb.broker.accesslayer.RsIterator] ERROR: Unable to build
object
>instance (MAYBE you don't have a constructor available):class dbsii.House
>org.apache.ojb.broker.PersistenceBrokerException: Unable to build object
>instance (MAYBE you don't have a constructor available):class dbsii.House
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithReflection(
R
>owReaderDefaultImpl.java:239)
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectFrom(RowRe
a
>derDefaultImpl.java:115)        at
>org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsItera
t
>or.java:428)
>        at
>org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:256)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:147)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:244)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:263)
>        at
>org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persi
s
>tenceBrokerImpl.java:998)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at org.apache.ojb.jdori.sql.OjbExtent.<init>(OjbExtent.java:98)
>        at
>org.apache.ojb.jdori.sql.OjbStoreManager.getExtent(OjbStoreManager.java:251
)
>        at com.sun.jdori.common.PersistenceManagerImpl.getExtent(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.checkCandidates(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.execute(Unknown Source)
>        at dbsii.Frontend.getHouseListings(Frontend.java:148)
>        at dbsii.Frontend.run(Frontend.java:68)
>        at dbsii.Frontend.main(Frontend.java:40)
>Caused by:
>org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: (Could
>not instantiate dbsii.House: Class
>org.apache.ojb.broker.util.ConstructorHelper can not access a member of
>class dbsii.House with modifiers "public")
>        at
>org.apache.ojb.broker.util.ConstructorHelper.instantiate(ConstructorHelper.
j
>ava:162)
>        at
>org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl.buildWithReflection(
R
>owReaderDefaultImpl.java:235)
>        ... 17 more
>Caused by: java.lang.IllegalAccessException: Class
>org.apache.ojb.broker.util.ConstructorHelper can not access
>a member of class dbsii.House with modifiers "public"
>        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
>        at java.lang.reflect.Constructor.newInstance(Constructor.java:268)
>        at
>org.apache.ojb.broker.util.ConstructorHelper.instantiate(ConstructorHelper.
j
>ava:158)
>        ... 18 more
>org.apache.ojb.broker.PersistenceBrokerException:
>java.util.NoSuchElementException: Could not obtain next object: Unable to
>build object instance (MAYBE you don't have a constructor available):class
>dbsii.House
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:251)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:263)
>        at
>org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Persi
s
>tenceBrokerImpl.java:998)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at
>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery
(
>DelegatingPersistenceBroker.java:322)
>        at org.apache.ojb.jdori.sql.OjbExtent.<init>(OjbExtent.java:98)
>        at
>org.apache.ojb.jdori.sql.OjbStoreManager.getExtent(OjbStoreManager.java:251
)
>        at com.sun.jdori.common.PersistenceManagerImpl.getExtent(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.checkCandidates(Unknown
>Source)
>        at com.sun.jdori.common.query.QueryImpl.execute(Unknown Source)
>        at dbsii.Frontend.getHouseListings(Frontend.java:148)
>        at dbsii.Frontend.run(Frontend.java:68)
>        at dbsii.Frontend.main(Frontend.java:40)
>Caused by: java.util.NoSuchElementException: Could not obtain next object:
>Unable to build object instance (MAYBE you don't have a constructor
>available):class dbsii.House
>        at
>org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:276)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:147)
>        at
>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryR
e
>ferenceBroker.java:244)
>        ... 12 more
>Exception in thread "main" javax.jdo.JDOUserException: Cannot close
>PersistenceManager while transaction is still active.
>        at com.sun.jdori.common.PersistenceManagerImpl.close(Unknown
Source)
>        at
>com.sun.jdori.common.PersistenceManagerImpl.popCurrentWrapper(Unknown
>Source)
>        at com.sun.jdori.common.PersistenceManagerWrapper.close(Unknown
>Source)
>        at dbsii.Frontend.getHouseListings(Frontend.java:170)
>        at dbsii.Frontend.run(Frontend.java:68)
>        at dbsii.Frontend.main(Frontend.java:40)
>
>
>
>
>
>-----Ursprüngliche Nachricht-----
>Von: Gus Heck [mailto:[EMAIL PROTECTED]
>Gesendet: Samstag, 20. Dezember 2003 00:17
>An: OJB Users List
>Betreff: Re: AW: AW: JDO - Unable to build object instance
>
>
>This may interest you:
>
>http://www.mail-archive.com/[EMAIL PROTECTED]/msg03320.html
>
>HTH,
>Gus
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to