You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sean Kleinjung <se...@satshot.com> on 2003/09/22 19:05:01 UTC

Only one insert succeeds per application deploy

Hello,

We are attempting to use the Object-Relational Bridge in a web
application that is being deployed to the Novell eXtend application
server. We seem to have gotten everything installed and configured
correctly, and are working through a simple servlet we wrote based
heavily on the ODMG tutorial.

We have, however, run into a bizarre problem. If we package and deploy
the web application, then call a servlet that is supposed to insert a
new (id,name) tuple into a test table, the operation succeeds. Once. If
we call the servlet multiple times, only the first object gets inserted.
Repeated calls appear to have no effect on the database. No exception or
error condition occurs, and as far as the servlet code can tell the
operation succeeds, but there is no change on the database.

Following is the code in question:

/*
 * SNIP
 */

public class TestServlet extends HttpServlet {
	Implementation odmg = null;

	/**
	 * 
	 */
	public TestServlet() {
		super();
	}
	
	
	/*
	 * @see javax.servlet.GenericServlet#init()
	 */
	public void init() throws ServletException {
		super.init();
		
		odmg = OJB.getInstance();
		Database db = odmg.newDatabase();
		try {
			db.open( "users", Database.OPEN_READ_WRITE);
		} catch (ODMGException ex) {
			throw new ServletException(
				"Failed to open database: ", ex);
		}
	}


	protected void doGet(HttpServletRequest req, 
				HttpServletResponse resp)
			throws ServletException, IOException {
		Test test = new Test();
		test.setName(req.getParameter("name"));

		Transaction tx = null;
		try {
			tx = odmg.newTransaction();
			tx.begin();
			tx.lock(test, Transaction.WRITE);
			tx.commit();
		} catch (LockNotGrantedException lnge) {
			//lnge.printStackTrace();
			throw new ServletException(lnge);
		}

		resp.getWriter().println("Done.");
	}
}

/*
 * /SNIP
 */

I tried an alternate implementation where the ODMG implementation object
and database objects were created/opened and closed during every
invocation of the servlet's doGet method, but this exhibited the same
effect.

We are stumped on this, and any help would be greatly appreciated.

Thanks for your time,
Sean Kleinjung
Web Application Developer
Agri ImaGIS Technologies, Inc.
http://www.satshot.com

--------------------------------------------------------------------------

For reference, the repository_user.xml file for this application is
included below:

--------------------------------------------------------------------------

<!-- Please keep user defined mappings in this file only
     to avoid mixing user defined and system mappings. -->
<!-- Mapping of User defined classes starts here -->

<!-- The mappings for the tutorial classes are placed here to make it
     easier to find them for OJB newbies.
     Please remove them if you don't need them in your environment. -->
     
     <!-- mssql database description -->
     <jdbc-connection-descriptor
     		jcd-alias="users"
     		platform="MsSQLServer"
     		jdbc-level="2.0"
     		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
     		

<!-- Definitions for com.satshot.test.Test -->
   <class-descriptor
   	  class="com.satshot.test.Test"
   	  table="Test"
   >
      <field-descriptor
         name="oid"
         column="oid"
         jdbc-type="INTEGER"
         primarykey="true"
         access="readonly"
      />
      <field-descriptor
         name="name"
         column="name"
         jdbc-type="VARCHAR"
      />
   </class-descriptor>


<!-- Mapping of User defined classes ends here -->


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Only one insert succeeds per application deploy

Posted by Nils Kalchhauser <ni...@vollwerbung.at>.
have you tried to put some debug output into your doGet method (like
System.out.println("doGet: done."); ) to see if it really gets called?
maybe your problem does not have to do with OJB but with some caching
issues...


Nils


Sean Kleinjung <se...@satshot.com> wrote (22 Sep 2003 12:05:01 -0500):
> Hello,
> 
> We are attempting to use the Object-Relational Bridge in a web
> application that is being deployed to the Novell eXtend application
> server. We seem to have gotten everything installed and configured
> correctly, and are working through a simple servlet we wrote based
> heavily on the ODMG tutorial.
> 
> We have, however, run into a bizarre problem. If we package and deploy
> the web application, then call a servlet that is supposed to insert a
> new (id,name) tuple into a test table, the operation succeeds. Once. If
> we call the servlet multiple times, only the first object gets inserted.
> Repeated calls appear to have no effect on the database. No exception or
> error condition occurs, and as far as the servlet code can tell the
> operation succeeds, but there is no change on the database.
> 
> Following is the code in question:
> 
> /*
>  * SNIP
>  */
> 
> public class TestServlet extends HttpServlet {
> 	Implementation odmg = null;
> 
> 	/**
> 	 * 
> 	 */
> 	public TestServlet() {
> 		super();
> 	}
> 	
> 	
> 	/*
> 	 * @see javax.servlet.GenericServlet#init()
> 	 */
> 	public void init() throws ServletException {
> 		super.init();
> 		
> 		odmg = OJB.getInstance();
> 		Database db = odmg.newDatabase();
> 		try {
> 			db.open( "users", Database.OPEN_READ_WRITE);
> 		} catch (ODMGException ex) {
> 			throw new ServletException(
> 				"Failed to open database: ", ex);
> 		}
> 	}
> 
> 
> 	protected void doGet(HttpServletRequest req, 
> 				HttpServletResponse resp)
> 			throws ServletException, IOException {
> 		Test test = new Test();
> 		test.setName(req.getParameter("name"));
> 
> 		Transaction tx = null;
> 		try {
> 			tx = odmg.newTransaction();
> 			tx.begin();
> 			tx.lock(test, Transaction.WRITE);
> 			tx.commit();
> 		} catch (LockNotGrantedException lnge) {
> 			//lnge.printStackTrace();
> 			throw new ServletException(lnge);
> 		}
> 
> 		resp.getWriter().println("Done.");
> 	}
> }
> 
> /*
>  * /SNIP
>  */
> 
> I tried an alternate implementation where the ODMG implementation object
> and database objects were created/opened and closed during every
> invocation of the servlet's doGet method, but this exhibited the same
> effect.
> 
> We are stumped on this, and any help would be greatly appreciated.
> 
> Thanks for your time,
> Sean Kleinjung
> Web Application Developer
> Agri ImaGIS Technologies, Inc.
> http://www.satshot.com
> 
> -----------------------------------------------------------------------
> ---
> 
> For reference, the repository_user.xml file for this application is
> included below:
> 
> -----------------------------------------------------------------------
> ---
> 
> <!-- Please keep user defined mappings in this file only
>      to avoid mixing user defined and system mappings. -->
> <!-- Mapping of User defined classes starts here -->
> 
> <!-- The mappings for the tutorial classes are placed here to make it
>      easier to find them for OJB newbies.
>      Please remove them if you don't need them in your environment. -->
>      
>      <!-- mssql database description -->
>      <jdbc-connection-descriptor
>      		jcd-alias="users"
>      		platform="MsSQLServer"
>      		jdbc-level="2.0"
>      		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
>      		
> 
> <!-- Definitions for com.satshot.test.Test -->
>    <class-descriptor
>    	  class="com.satshot.test.Test"
>    	  table="Test"
>    >
>       <field-descriptor
>          name="oid"
>          column="oid"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          access="readonly"
>       />
>       <field-descriptor
>          name="name"
>          column="name"
>          jdbc-type="VARCHAR"
>       />
>    </class-descriptor>
> 
> 
> <!-- Mapping of User defined classes ends here -->
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Only one insert succeeds per application deploy

Posted by Thomas Mahler <th...@web.de>.
Hi Sean,

You are encountering a typical getting started problem with the ODMG API.
You always have to keep in mind that ODMG works a object level 
transaction manager. It only performs database operations if it Objects 
  are new or if there have been changes *during* the current transaction.

This explains exactly your situation:
The first time OJB/ODMG detects that  the object test is new during
tx.lock(test, Transaction.WRITE);

In the subsequent runs it detects that test is an existing object in the 
database. As there are no changes to test between the
tx.lock(test, Transaction.WRITE);

and
tx.commit();

nothing happens.

The solution:
call
test.setXXX(...);
to modify the object *during* the transaction.

If you are receiving a changed version of test from GUI
you can call

((TransactionExt) tx).markDirty(test);

This will inform the transaction that the object has been modified 
outside the transaction and that an UPDATE has to be executed.

cheers,
Thomas

Sean Kleinjung wrote:
> Hello,
> 
> We are attempting to use the Object-Relational Bridge in a web
> application that is being deployed to the Novell eXtend application
> server. We seem to have gotten everything installed and configured
> correctly, and are working through a simple servlet we wrote based
> heavily on the ODMG tutorial.
> 
> We have, however, run into a bizarre problem. If we package and deploy
> the web application, then call a servlet that is supposed to insert a
> new (id,name) tuple into a test table, the operation succeeds. Once. If
> we call the servlet multiple times, only the first object gets inserted.
> Repeated calls appear to have no effect on the database. No exception or
> error condition occurs, and as far as the servlet code can tell the
> operation succeeds, but there is no change on the database.
> 
> Following is the code in question:
> 
> /*
>  * SNIP
>  */
> 
> public class TestServlet extends HttpServlet {
> 	Implementation odmg = null;
> 
> 	/**
> 	 * 
> 	 */
> 	public TestServlet() {
> 		super();
> 	}
> 	
> 	
> 	/*
> 	 * @see javax.servlet.GenericServlet#init()
> 	 */
> 	public void init() throws ServletException {
> 		super.init();
> 		
> 		odmg = OJB.getInstance();
> 		Database db = odmg.newDatabase();
> 		try {
> 			db.open( "users", Database.OPEN_READ_WRITE);
> 		} catch (ODMGException ex) {
> 			throw new ServletException(
> 				"Failed to open database: ", ex);
> 		}
> 	}
> 
> 
> 	protected void doGet(HttpServletRequest req, 
> 				HttpServletResponse resp)
> 			throws ServletException, IOException {
> 		Test test = new Test();
> 		test.setName(req.getParameter("name"));
> 
> 		Transaction tx = null;
> 		try {
> 			tx = odmg.newTransaction();
> 			tx.begin();
> 			tx.lock(test, Transaction.WRITE);
> 			tx.commit();
> 		} catch (LockNotGrantedException lnge) {
> 			//lnge.printStackTrace();
> 			throw new ServletException(lnge);
> 		}
> 
> 		resp.getWriter().println("Done.");
> 	}
> }
> 
> /*
>  * /SNIP
>  */
> 
> I tried an alternate implementation where the ODMG implementation object
> and database objects were created/opened and closed during every
> invocation of the servlet's doGet method, but this exhibited the same
> effect.
> 
> We are stumped on this, and any help would be greatly appreciated.
> 
> Thanks for your time,
> Sean Kleinjung
> Web Application Developer
> Agri ImaGIS Technologies, Inc.
> http://www.satshot.com
> 
> --------------------------------------------------------------------------
> 
> For reference, the repository_user.xml file for this application is
> included below:
> 
> --------------------------------------------------------------------------
> 
> <!-- Please keep user defined mappings in this file only
>      to avoid mixing user defined and system mappings. -->
> <!-- Mapping of User defined classes starts here -->
> 
> <!-- The mappings for the tutorial classes are placed here to make it
>      easier to find them for OJB newbies.
>      Please remove them if you don't need them in your environment. -->
>      
>      <!-- mssql database description -->
>      <jdbc-connection-descriptor
>      		jcd-alias="users"
>      		platform="MsSQLServer"
>      		jdbc-level="2.0"
>      		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
>      		
> 
> <!-- Definitions for com.satshot.test.Test -->
>    <class-descriptor
>    	  class="com.satshot.test.Test"
>    	  table="Test"
>    >
>       <field-descriptor
>          name="oid"
>          column="oid"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          access="readonly"
>       />
>       <field-descriptor
>          name="name"
>          column="name"
>          jdbc-type="VARCHAR"
>       />
>    </class-descriptor>
> 
> 
> <!-- Mapping of User defined classes ends here -->
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: Only one insert succeeds per application deploy

Posted by Sean Kleinjung <se...@satshot.com>.
I have gotten several responses on this issue, but unfortunately none of
them seem to have worked. I have changed the code as detailed at the end
of this mail's text. I will go through a summary of what has been
suggested, and why it did not work now.

Joss Wright wrote:

> This reminds me of a similar problem I had while using 
> PersistenceBroker, I believe I had to call broker.close() in a finally
> block to resolve the problem:
> 
> *** SNIP
>
> I'm not familiar with ODMG but is there an odmg.close() method that needs to
> be called?

There is nothing that appears to be the equivalent of a close() method
in the ODMG Implementation interface. I have modified the code to
re-open and close the database object each time it is used, instead of
only when the servlet is deployed/undeployed. However, this appears to
have had no effect.

Nils Kalchhauser wrote:

> have you tried to put some debug output into your doGet method (like
> System.out.println("doGet: done."); ) to see if it really gets called?
> maybe your problem does not have to do with OJB but with some caching
> issues...

There is copious amounts of debugging output in the actual code. I
removed these statements from the attached source code to make the
code's intent clearer and avoid excess clutter. We have verified that
the servlet's doGet method is, in fact, being called.

Thomas Mahler wrote:

> *** SNIP
>
> The first time OJB/ODMG detects that the object test is new during
> tx.lock(test, Transaction.WRITE);
>
> In the subsequent runs it detects that test is an existing object in 
> the database. As there are no changes to test between the  
> tx.lock(test, Transaction.WRITE); and tx.commit(); nothing happens.

The intent of the servlet is to take as a parameter an object name, and
insert a new object into the database with this name. Thus, expected
behavior is that during every execution of the servlet, the persistence
layer should detect the 'test' object as a new object. I assumed this
would be the case, since I am not doing any kind of query to retrieve
the object from the database, but rather instantiating a new one in the
code.

What method does OJB use to detect that an object already exists in the
database, and how can I force it to insert a new one rather than
attempting to update an existing one?

> The solution: 
> call test.setXXX(...); to modify the object *during* the transaction.

As shown in the update source code I have attached, I have modified the
doGet method to perform all relevant methods during the transaction.
However, the original behavior is still being exhibited.

Michael Becke wrote:

> Part of the problem could also be that you are using the  
> SequenceManagerNativeImpl.  Please see the following bug for details  
> <http://scarab.werken.com/issues/id/OJB204>.

I have read through the indicated bug report. It appears to be an issue
that occurs when multiple INSERTs are performed during the same
transaction. I will need to revisit this issue in the future possibly,
but the present code is only inserting one object per transaction, so
should not be affected by this issue.

Followup:

However, I am curious as to what the SequenceManagerNativeImpl class is,
and how you know that we are using it. This leads into a possible
problem with our configuration that we have discussed here, and I will
outline below.

The application that we are creating will be integrating with a legacy
database that is used by numerous PHP applications that require the
primary key to be an identity column in our MS SQL database. Thus it is
not possible to use a Java-based mechanism for generating OIDs.

Examining the repository_user.xml file I attached with my original
message shows that we have marked the 'oid' column with 'readonly'
access. Our intent in doing so was that when inserting a new object, OJB
would not try to supply a primary key, nor modify it later. Thus, the
key that was automatically generated by SQL Server would be used. 

Is this an improper usage of OJB that might be causing our problem? If
so, what is the recommended manner with which to handle database
identity columns used as primary keys?

Also, in examing the supplied test case for the issue mentioned by
Brian, I noticed that inserts were attempted via the makePersistent
method of the Database interface. The tutorial seems to indicate that
there is no explicit method call required in order add an object, but
rather locking it should implicitly add it to the database. In the
interest of being thorough, however, I tried calling makePersistent with
the new object instead of simply securing a write lock on it. This did
not, however, solve the problem.

Sorry this is so long...Just trying to supply enough information so that
someone can (hopefully) help with this problem. 

Thanks for your time, and any assistance is greatly appreciated,
Sean Kleinjung
Web Application Developer
Agri ImaGIS Technologies, Inc.
http://www.satshot.com


Modified source code for the doGet method is attached below. This code
still exhibits the original problem.
------------------------------------------------------------------------

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {		
	Database db = odmg.newDatabase();
	try {
		db.open( "users", Database.OPEN_READ_WRITE);
	} catch (ODMGException ex) {
		throw new ServletException(
			"Failed to open database: ", 
			ex);
	}		

	Transaction tx = null;
	try {
		tx = odmg.newTransaction();		
		tx.begin();		
		Test test = new Test();
		test.setName(req.getParameter("name"));	
		db.makePersistent(test);
		tx.commit();
	} catch (LockNotGrantedException lnge) {
		//lnge.printStackTrace();
		throw new ServletException(lnge);
	}

	try {
		db.close();
	} catch (ODMGException e) {
		throw new ServletException(
			"Failed to close database: ", 
			e);
	}

	resp.getWriter().println("Done.");
}

> > -----Original Message-----
> > From: Sean Kleinjung [mailto:sean@satshot.com]
> > Sent: 22 September 2003 18:05
> > To: ojb-user@db.apache.org
> > Subject: Only one insert succeeds per application deploy
> >
> >
> > Hello,
> >
> > We are attempting to use the Object-Relational Bridge in a web
> > application that is being deployed to the Novell eXtend application
> > server. We seem to have gotten everything installed and configured
> > correctly, and are working through a simple servlet we wrote based
> > heavily on the ODMG tutorial.
> >
> > We have, however, run into a bizarre problem. If we package and deploy
> > the web application, then call a servlet that is supposed to insert a
> > new (id,name) tuple into a test table, the operation succeeds. Once. If
> > we call the servlet multiple times, only the first object gets inserted.
> > Repeated calls appear to have no effect on the database. No exception or
> > error condition occurs, and as far as the servlet code can tell the
> > operation succeeds, but there is no change on the database.
> >
> > Following is the code in question:
> >
> > /*
> >  * SNIP
> >  */
> >
> > public class TestServlet extends HttpServlet {
> > 	Implementation odmg = null;
> >
> > 	/**
> > 	 *
> > 	 */
> > 	public TestServlet() {
> > 		super();
> > 	}
> >
> >
> > 	/*
> > 	 * @see javax.servlet.GenericServlet#init()
> > 	 */
> > 	public void init() throws ServletException {
> > 		super.init();
> >
> > 		odmg = OJB.getInstance();
> > 		Database db = odmg.newDatabase();
> > 		try {
> > 			db.open( "users", Database.OPEN_READ_WRITE);
> > 		} catch (ODMGException ex) {
> > 			throw new ServletException(
> > 				"Failed to open database: ", ex);
> > 		}
> > 	}
> >
> >
> > 	protected void doGet(HttpServletRequest req,
> > 				HttpServletResponse resp)
> > 			throws ServletException, IOException {
> > 		Test test = new Test();
> > 		test.setName(req.getParameter("name"));
> >
> > 		Transaction tx = null;
> > 		try {
> > 			tx = odmg.newTransaction();
> > 			tx.begin();
> > 			tx.lock(test, Transaction.WRITE);
> > 			tx.commit();
> > 		} catch (LockNotGrantedException lnge) {
> > 			//lnge.printStackTrace();
> > 			throw new ServletException(lnge);
> > 		}
> >
> > 		resp.getWriter().println("Done.");
> > 	}
> > }
> >
> > /*
> >  * /SNIP
> >  */
> >
> > I tried an alternate implementation where the ODMG implementation object
> > and database objects were created/opened and closed during every
> > invocation of the servlet's doGet method, but this exhibited the same
> > effect.
> >
> > We are stumped on this, and any help would be greatly appreciated.
> >
> > Thanks for your time,
> > Sean Kleinjung
> > Web Application Developer
> > Agri ImaGIS Technologies, Inc.
> > http://www.satshot.com
> >
> > --------------------------------------------------------------------------
> >
> > For reference, the repository_user.xml file for this application is
> > included below:
> >
> > --------------------------------------------------------------------------
> >
> > <!-- Please keep user defined mappings in this file only
> >      to avoid mixing user defined and system mappings. -->
> > <!-- Mapping of User defined classes starts here -->
> >
> > <!-- The mappings for the tutorial classes are placed here to make it
> >      easier to find them for OJB newbies.
> >      Please remove them if you don't need them in your environment. -->
> >
> >      <!-- mssql database description -->
> >      <jdbc-connection-descriptor
> >      		jcd-alias="users"
> >      		platform="MsSQLServer"
> >      		jdbc-level="2.0"
> >      		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
> >
> >
> > <!-- Definitions for com.satshot.test.Test -->
> >    <class-descriptor
> >    	  class="com.satshot.test.Test"
> >    	  table="Test"
> >    >
> >       <field-descriptor
> >          name="oid"
> >          column="oid"
> >          jdbc-type="INTEGER"
> >          primarykey="true"
> >          access="readonly"
> >       />
> >       <field-descriptor
> >          name="name"
> >          column="name"
> >          jdbc-type="VARCHAR"
> >       />
> >    </class-descriptor>
> >
> >
> > <!-- Mapping of User defined classes ends here -->
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: Only one insert succeeds per application deploy

Posted by Joss Wright <jo...@talk21.com>.
Sean,

This reminds me of a similar problem I had while using PersistenceBroker, I
believe I had to call broker.close() in a finally block to resolve the
problem:

	PersistenceBroker broker = null;
	try {
		broker = broker = PersistenceBrokerFactory.defaultPersistenceBroker();
		broker.beginTransaction();
		broker.store(myTransferObject);
		broker.commitTransaction();
	} catch (PersistenceBrokerException e) {
		broker.abortTransaction();
	} finally {
		if (broker != null) {
			broker.close(); //must close broker
		}
	}

I'm not familiar with ODMG but is there an odmg.close() method that needs to
be called?

Hope this helps,

Joss



> -----Original Message-----
> From: Sean Kleinjung [mailto:sean@satshot.com]
> Sent: 22 September 2003 18:05
> To: ojb-user@db.apache.org
> Subject: Only one insert succeeds per application deploy
>
>
> Hello,
>
> We are attempting to use the Object-Relational Bridge in a web
> application that is being deployed to the Novell eXtend application
> server. We seem to have gotten everything installed and configured
> correctly, and are working through a simple servlet we wrote based
> heavily on the ODMG tutorial.
>
> We have, however, run into a bizarre problem. If we package and deploy
> the web application, then call a servlet that is supposed to insert a
> new (id,name) tuple into a test table, the operation succeeds. Once. If
> we call the servlet multiple times, only the first object gets inserted.
> Repeated calls appear to have no effect on the database. No exception or
> error condition occurs, and as far as the servlet code can tell the
> operation succeeds, but there is no change on the database.
>
> Following is the code in question:
>
> /*
>  * SNIP
>  */
>
> public class TestServlet extends HttpServlet {
> 	Implementation odmg = null;
>
> 	/**
> 	 *
> 	 */
> 	public TestServlet() {
> 		super();
> 	}
>
>
> 	/*
> 	 * @see javax.servlet.GenericServlet#init()
> 	 */
> 	public void init() throws ServletException {
> 		super.init();
>
> 		odmg = OJB.getInstance();
> 		Database db = odmg.newDatabase();
> 		try {
> 			db.open( "users", Database.OPEN_READ_WRITE);
> 		} catch (ODMGException ex) {
> 			throw new ServletException(
> 				"Failed to open database: ", ex);
> 		}
> 	}
>
>
> 	protected void doGet(HttpServletRequest req,
> 				HttpServletResponse resp)
> 			throws ServletException, IOException {
> 		Test test = new Test();
> 		test.setName(req.getParameter("name"));
>
> 		Transaction tx = null;
> 		try {
> 			tx = odmg.newTransaction();
> 			tx.begin();
> 			tx.lock(test, Transaction.WRITE);
> 			tx.commit();
> 		} catch (LockNotGrantedException lnge) {
> 			//lnge.printStackTrace();
> 			throw new ServletException(lnge);
> 		}
>
> 		resp.getWriter().println("Done.");
> 	}
> }
>
> /*
>  * /SNIP
>  */
>
> I tried an alternate implementation where the ODMG implementation object
> and database objects were created/opened and closed during every
> invocation of the servlet's doGet method, but this exhibited the same
> effect.
>
> We are stumped on this, and any help would be greatly appreciated.
>
> Thanks for your time,
> Sean Kleinjung
> Web Application Developer
> Agri ImaGIS Technologies, Inc.
> http://www.satshot.com
>
> --------------------------------------------------------------------------
>
> For reference, the repository_user.xml file for this application is
> included below:
>
> --------------------------------------------------------------------------
>
> <!-- Please keep user defined mappings in this file only
>      to avoid mixing user defined and system mappings. -->
> <!-- Mapping of User defined classes starts here -->
>
> <!-- The mappings for the tutorial classes are placed here to make it
>      easier to find them for OJB newbies.
>      Please remove them if you don't need them in your environment. -->
>
>      <!-- mssql database description -->
>      <jdbc-connection-descriptor
>      		jcd-alias="users"
>      		platform="MsSQLServer"
>      		jdbc-level="2.0"
>      		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
>
>
> <!-- Definitions for com.satshot.test.Test -->
>    <class-descriptor
>    	  class="com.satshot.test.Test"
>    	  table="Test"
>    >
>       <field-descriptor
>          name="oid"
>          column="oid"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          access="readonly"
>       />
>       <field-descriptor
>          name="name"
>          column="name"
>          jdbc-type="VARCHAR"
>       />
>    </class-descriptor>
>
>
> <!-- Mapping of User defined classes ends here -->
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Only one insert succeeds per application deploy

Posted by Michael Becke <be...@u.washington.edu>.
Hi Sean,

Part of the problem could also be that you are using the  
SequenceManagerNativeImpl.  Please see the following bug for details  
<http://scarab.werken.com/issues/id/OJB204>.

Mike

On Monday, September 22, 2003, at 01:05 PM, Sean Kleinjung wrote:

> Hello,
>
> We are attempting to use the Object-Relational Bridge in a web
> application that is being deployed to the Novell eXtend application
> server. We seem to have gotten everything installed and configured
> correctly, and are working through a simple servlet we wrote based
> heavily on the ODMG tutorial.
>
> We have, however, run into a bizarre problem. If we package and deploy
> the web application, then call a servlet that is supposed to insert a
> new (id,name) tuple into a test table, the operation succeeds. Once. If
> we call the servlet multiple times, only the first object gets  
> inserted.
> Repeated calls appear to have no effect on the database. No exception  
> or
> error condition occurs, and as far as the servlet code can tell the
> operation succeeds, but there is no change on the database.
>
> Following is the code in question:
>
> /*
>  * SNIP
>  */
>
> public class TestServlet extends HttpServlet {
> 	Implementation odmg = null;
>
> 	/**
> 	 *
> 	 */
> 	public TestServlet() {
> 		super();
> 	}
> 	
> 	
> 	/*
> 	 * @see javax.servlet.GenericServlet#init()
> 	 */
> 	public void init() throws ServletException {
> 		super.init();
> 		
> 		odmg = OJB.getInstance();
> 		Database db = odmg.newDatabase();
> 		try {
> 			db.open( "users", Database.OPEN_READ_WRITE);
> 		} catch (ODMGException ex) {
> 			throw new ServletException(
> 				"Failed to open database: ", ex);
> 		}
> 	}
>
>
> 	protected void doGet(HttpServletRequest req,
> 				HttpServletResponse resp)
> 			throws ServletException, IOException {
> 		Test test = new Test();
> 		test.setName(req.getParameter("name"));
>
> 		Transaction tx = null;
> 		try {
> 			tx = odmg.newTransaction();
> 			tx.begin();
> 			tx.lock(test, Transaction.WRITE);
> 			tx.commit();
> 		} catch (LockNotGrantedException lnge) {
> 			//lnge.printStackTrace();
> 			throw new ServletException(lnge);
> 		}
>
> 		resp.getWriter().println("Done.");
> 	}
> }
>
> /*
>  * /SNIP
>  */
>
> I tried an alternate implementation where the ODMG implementation  
> object
> and database objects were created/opened and closed during every
> invocation of the servlet's doGet method, but this exhibited the same
> effect.
>
> We are stumped on this, and any help would be greatly appreciated.
>
> Thanks for your time,
> Sean Kleinjung
> Web Application Developer
> Agri ImaGIS Technologies, Inc.
> http://www.satshot.com
>
> ----------------------------------------------------------------------- 
> ---
>
> For reference, the repository_user.xml file for this application is
> included below:
>
> ----------------------------------------------------------------------- 
> ---
>
> <!-- Please keep user defined mappings in this file only
>      to avoid mixing user defined and system mappings. -->
> <!-- Mapping of User defined classes starts here -->
>
> <!-- The mappings for the tutorial classes are placed here to make it
>      easier to find them for OJB newbies.
>      Please remove them if you don't need them in your environment. -->
>
>      <!-- mssql database description -->
>      <jdbc-connection-descriptor
>      		jcd-alias="users"
>      		platform="MsSQLServer"
>      		jdbc-level="2.0"
>      		jndi-datasource-name="java:comp/env/jdbc/UsersDB"/>
>      		
>
> <!-- Definitions for com.satshot.test.Test -->
>    <class-descriptor
>    	  class="com.satshot.test.Test"
>    	  table="Test"
>>
>       <field-descriptor
>          name="oid"
>          column="oid"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          access="readonly"
>       />
>       <field-descriptor
>          name="name"
>          column="name"
>          jdbc-type="VARCHAR"
>       />
>    </class-descriptor>
>
>
> <!-- Mapping of User defined classes ends here -->
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org