You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by mauro2java2011 <ma...@gmail.com> on 2013/04/03 16:12:08 UTC

web application not work with db mysql and derby

i have write a simple web applciation with ejb and @Inject it into 2 Servlet
.
But i get the following exception :

java.lang.NullPointerException at
srv2.Servlet1.processRequest(Servlet1.java:45) at
srv2.Servlet1.doGet(Servlet1.java:84) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) 


whi?
what it is the error?




--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Declare both in tomee.xml and reference them in persistence.xml.
Le 4 avr. 2013 19:57, "mauro2java2011" <ma...@gmail.com> a écrit :

> Finally i have to declare the  non JTA datasource only into the tomee.xml
> or
> resources.xml with
>  JtaManaged false
>
>  or also into the persistence.xml?
> into the response above it is set only the <jta-data-souce>
>
> The following properties i have to set it into the declaration of resource
> for mysql? or if i not declare it ,  the value of  properties for default
> how it is?
>
>  .................................................
>   jmxEnabled true
>   LogSql false
>   InitialSize 10
>   MaxActive 100
>   MaxIdle 30
>   MaxWait 10000
>   minIdle 10
>   suspectTimeout 60
>   removeAbandoned true
>   removeAbandonedTimeout 180
>   timeBetweenEvictionRunsMillis 30000
>   jdbcInterceptors=StatementCache(max=128)
> ...................................................
>
> what it is the:
>   jmxEnable true???
> what it is the:
> jdbcInterceptors=StatementCache(max=128)  ?????
>
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4662000.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: web application not work with db mysql and derby

Posted by mauro2java2011 <ma...@gmail.com>.
Finally i have to declare the  non JTA datasource only into the tomee.xml or
resources.xml with 
 JtaManaged false

 or also into the persistence.xml?
into the response above it is set only the <jta-data-souce>

The following properties i have to set it into the declaration of resource 
for mysql? or if i not declare it ,  the value of  properties for default
how it is?

 .................................................
  jmxEnabled true
  LogSql false
  InitialSize 10
  MaxActive 100
  MaxIdle 30
  MaxWait 10000
  minIdle 10
  suspectTimeout 60
  removeAbandoned true
  removeAbandonedTimeout 180
  timeBetweenEvictionRunsMillis 30000
  jdbcInterceptors=StatementCache(max=128) 
...................................................

what it is the:
  jmxEnable true???
what it is the:
jdbcInterceptors=StatementCache(max=128)  ?????











--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4662000.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Understood.

Clarification (or what I meant to say), per my experience,

1. it is not necessary for 'tomee' users to add non-jta datasource in
persistence.xml
2. it is not necessary for 'tomee' users to add non-jta datasource in
tomee.xml

Why/proof? My latest/current persistence.xml includes the following:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
    <persistence-unit name="mcmsPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/mcmsJta</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
        <property name="eclipselink.target-database"

value="org.eclipse.persistence.platform.database.DerbyPlatform"/>
        <property name="eclipselink.jdbc.cache-statements" value="true" />
        <property name="eclipselink.jdbc.cache-statements.size" value="128"
/>
        <property name="eclipselink.logging.parameters" value="false" />
        </properties>
    </persistence-unit>
</persistence>


My tomee.xml does 'not' have non-jta datasource, but when tomee (1.6.0
snapshot) is started, I see the following in the log (which tells me that
'tomee' created non-jta, since I did not specify non-jta 'anywhere' in my
app. TomEE container/committers is/are NICE!!! :)

Apr 04, 2013 1:59:55 AM org.apache.openejb.config.AutoConfig
setNonJtaDataSource
INFO: Adjusting PersistenceUnit mcmsPU <non-jta-data-source> to Resource ID
'jdbc/mcmsJtaNonJta' from 'null'


Recognize/note the word 'adjusting' in the log above. :)



On Thu, Apr 4, 2013 at 9:29 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:

> both are necessary since years since the jpa provider can use both (for
> action not in a JTA context for instance). OpenJPA needs it for instance.
>
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> *Blog: **http://rmannibucau.wordpress.com/*<
> http://rmannibucau.wordpress.com/>
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> *Github: https://github.com/rmannibucau*
>
>
>
> 2013/4/4 Howard W. Smith, Jr. <sm...@gmail.com>
>
> > On Thu, Apr 4, 2013 at 7:36 AM, mauro2java2011 <mauro2java2011@gmail.com
> > >wrote:
> >
> > > I have also to declare always the resource for non jta datasource with
> > jta
> > > false ?
> > > Whi into petsistece.xml ir is necessary to specify bot jta-datasource
> and
> > > nojtA-datasource?
> > >
> > >
> > From what I understand, it is no longer necessary to set 'both' jta and
> > non-jta datasource in persistence.xml. no longer necessary = 1.5.2 or
> 1.6.0
> > snapshot. If you're using 1.5.1, then it 'may' be necessary, but I don't
> > know. I don't use the 'release', I use 'snapshot'...always (since
> > 'snapshot' = 'latest version').
> >
> >
> >
> > > What it is the difference from the datasource pooled getting from
> normal
> > > tomcat  ? I refer to datasource fir poolig connection thar into tomcat
> i
> > > declare into context.xml and i refer it into web.xml into reference ??
> > >
> > >
> > I will let Romain reply to this. I think tomee.xml is recommended, and in
> > my case, context.xml and web.xml is not necessary.
> >
>

Re: web application not work with db mysql and derby

Posted by Romain Manni-Bucau <rm...@gmail.com>.
both are necessary since years since the jpa provider can use both (for
action not in a JTA context for instance). OpenJPA needs it for instance.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/4 Howard W. Smith, Jr. <sm...@gmail.com>

> On Thu, Apr 4, 2013 at 7:36 AM, mauro2java2011 <mauro2java2011@gmail.com
> >wrote:
>
> > I have also to declare always the resource for non jta datasource with
> jta
> > false ?
> > Whi into petsistece.xml ir is necessary to specify bot jta-datasource and
> > nojtA-datasource?
> >
> >
> From what I understand, it is no longer necessary to set 'both' jta and
> non-jta datasource in persistence.xml. no longer necessary = 1.5.2 or 1.6.0
> snapshot. If you're using 1.5.1, then it 'may' be necessary, but I don't
> know. I don't use the 'release', I use 'snapshot'...always (since
> 'snapshot' = 'latest version').
>
>
>
> > What it is the difference from the datasource pooled getting from normal
> > tomcat  ? I refer to datasource fir poolig connection thar into tomcat i
> > declare into context.xml and i refer it into web.xml into reference ??
> >
> >
> I will let Romain reply to this. I think tomee.xml is recommended, and in
> my case, context.xml and web.xml is not necessary.
>

Re: web application not work with db mysql and derby

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Thu, Apr 4, 2013 at 7:36 AM, mauro2java2011 <ma...@gmail.com>wrote:

> I have also to declare always the resource for non jta datasource with jta
> false ?
> Whi into petsistece.xml ir is necessary to specify bot jta-datasource and
> nojtA-datasource?
>
>
>From what I understand, it is no longer necessary to set 'both' jta and
non-jta datasource in persistence.xml. no longer necessary = 1.5.2 or 1.6.0
snapshot. If you're using 1.5.1, then it 'may' be necessary, but I don't
know. I don't use the 'release', I use 'snapshot'...always (since
'snapshot' = 'latest version').



> What it is the difference from the datasource pooled getting from normal
> tomcat  ? I refer to datasource fir poolig connection thar into tomcat i
> declare into context.xml and i refer it into web.xml into reference ??
>
>
I will let Romain reply to this. I think tomee.xml is recommended, and in
my case, context.xml and web.xml is not necessary.

Re: web application not work with db mysql and derby

Posted by mauro2java2011 <ma...@gmail.com>.
I have also to declare always the resource for non jta datasource with jta
false ?
Whi into petsistece.xml ir is necessary to specify bot jta-datasource and
nojtA-datasource?

What it is the difference from the datasource pooled getting from normal
tomcat  ? I refer to datasource fir poolig connection thar into tomcat i
declare into context.xml and i refer it into web.xml into reference ??

Mauro.
 Il giorno 04/apr/2013 13.20, "smithh032772 [via OpenEJB]" <
ml-node+s979440n4661985h10@n4.nabble.com> ha scritto:

> On Thu, Apr 4, 2013 at 7:07 AM, Romain Manni-Bucau <[hidden email]<http://user/SendEmail.jtp?type=node&node=4661985&i=0>>wrote:
>
>
> >
> > about the jta datasource define a datasource in tomee.xml with
> JtaManaged =
> > true and check you rpersistence.xml is of transaction-type = JTA
> >
> >
> For an example of what Romain is talking about above, see below (copied
> and
> pasted from an older mail thread, where this was discussed earlier.
>
> I am specifying my datasource(s) in tomee.xml, it references the
> jta-data-source name as defined inpersistence.xml. I would assume this is
> sufficient to specify as many persistence providers inpersistence.xml and
> as many resources in tomee.xml which reference jta-data-source name's
> defined in persistence.xml.
>
> So, my tomee.xml contains the following:
>
> <Resource id="jdbc/mcmsJta" type="javax.sql.DataSource">
>   JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
>   JdbcUrl jdbc:derby:C:/javadb/databases/mcmsdev;create=true
>   UserName ...
>   Password ...
>   JtaManaged true
>   jmxEnabled true
>   LogSql false
>   InitialSize 10
>   MaxActive 100
>   MaxIdle 30
>   MaxWait 10000
>   minIdle 10
>   suspectTimeout 60
>   removeAbandoned true
>   removeAbandonedTimeout 180
>   timeBetweenEvictionRunsMillis 30000
>   jdbcInterceptors=StatementCache(max=128)
> </Resource>
>
>
> and persistence.xml contains the following:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.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_2_0.xsd">
>     <persistence-unit name="mcmsPU" transaction-type="JTA">
>
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>         <jta-data-source>jdbc/mcmsJta</jta-data-source>
>         <non-jta-data-source>jdbc/mcmsNonJta</non-jta-data-source>
>         <exclude-unlisted-classes>false</exclude-unlisted-classes>
>         <properties>
>         <property name="eclipselink.target-database"
>                   value="org.eclipse.persistence
> .platform.database.DerbyPlatform"/>
>         <property name="eclipselink.jdbc.cache-statements" value="true" />
>         <property name="eclipselink.jdbc.cache-statements.size"
> value="100"
> />
>         <property name="eclipselink.logging.parameters" value="false" />
>         </properties>
>     </persistence-unit>
> </persistence>
>
>
> I'm sure you will find earlier topics discussed in this list, if you go to
> google and search for:
>
> tomee.xml  resource persistence.xml JTA openejb
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661985.html
>  To unsubscribe from web application not work with db mysql and derby, click
> here<http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4661958&code=bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDQ2NjE5NTh8LTExMTcxODc2MjU=>
> .
> NAML<http://openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661986.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Thu, Apr 4, 2013 at 7:07 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:

>
> about the jta datasource define a datasource in tomee.xml with JtaManaged =
> true and check you rpersistence.xml is of transaction-type = JTA
>
>
For an example of what Romain is talking about above, see below (copied and
pasted from an older mail thread, where this was discussed earlier.

I am specifying my datasource(s) in tomee.xml, it references the
jta-data-source name as defined inpersistence.xml. I would assume this is
sufficient to specify as many persistence providers inpersistence.xml and
as many resources in tomee.xml which reference jta-data-source name's
defined in persistence.xml.

So, my tomee.xml contains the following:

<Resource id="jdbc/mcmsJta" type="javax.sql.DataSource">
  JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
  JdbcUrl jdbc:derby:C:/javadb/databases/mcmsdev;create=true
  UserName ...
  Password ...
  JtaManaged true
  jmxEnabled true
  LogSql false
  InitialSize 10
  MaxActive 100
  MaxIdle 30
  MaxWait 10000
  minIdle 10
  suspectTimeout 60
  removeAbandoned true
  removeAbandonedTimeout 180
  timeBetweenEvictionRunsMillis 30000
  jdbcInterceptors=StatementCache(max=128)
</Resource>


and persistence.xml contains the following:


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
    <persistence-unit name="mcmsPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/mcmsJta</jta-data-source>
        <non-jta-data-source>jdbc/mcmsNonJta</non-jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
        <property name="eclipselink.target-database"
                  value="org.eclipse.persistence
.platform.database.DerbyPlatform"/>
        <property name="eclipselink.jdbc.cache-statements" value="true" />
        <property name="eclipselink.jdbc.cache-statements.size" value="100"
/>
        <property name="eclipselink.logging.parameters" value="false" />
        </properties>
    </persistence-unit>
</persistence>


I'm sure you will find earlier topics discussed in this list, if you go to
google and search for:

tomee.xml  resource persistence.xml JTA openejb

Re: web application not work with db mysql and derby

Posted by Romain Manni-Bucau <rm...@gmail.com>.
ant doesn't buil dyou rapp since it depends on netbeans

about the jta datasource define a datasource in tomee.xml with JtaManaged =
true and check you rpersistence.xml is of transaction-type = JTA

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/4 mauro2java2011 <ma...@gmail.com>

> whi is not buidable?
>
> i not understand on datasource JTA
> ?
> you can explique me ?
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661983.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: web application not work with db mysql and derby

Posted by mauro2java2011 <ma...@gmail.com>.
whi is not buidable?

i not understand on datasource JTA
?
you can explique me ?




--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661983.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

it is discovered from the datasource generally in jta mode.

aout your sample it is not buildable

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



2013/4/4 mauro2java2011 <ma...@gmail.com>

> hi from Mauro.
>  how you have request, i you send the link of my repo of my project with
> problems at Servelt like i have  write into the tomee forum.
>
>
> git://github.com/maurojava/web_application_not_work.git
> https://github.com/maurojava/web_application_not_work.git
>
> tank you for your attention.
>
> Another questions.
> into the application i have used a datasource derby .
>
> I have put into tomee/lib the jar of JDBC driver client.
> I have also put into the TOmEE/lib  the mysql driver.
>
> Into the persistence.xml i have also to specify the openJPA dialect for
> Derby or for mysql if i use it or it is automatic from the classpath ?
> And if it is necessary, how i can make it ?
> i have read that for mysql openJPA can have problems.
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661981.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: web application not work with db mysql and derby

Posted by mauro2java2011 <ma...@gmail.com>.
hi from Mauro.
 how you have request, i you send the link of my repo of my project with
problems at Servelt like i have  write into the tomee forum.


git://github.com/maurojava/web_application_not_work.git
https://github.com/maurojava/web_application_not_work.git

tank you for your attention.

Another questions.
into the application i have used a datasource derby .

I have put into tomee/lib the jar of JDBC driver client.
I have also put into the TOmEE/lib  the mysql driver.

Into the persistence.xml i have also to specify the openJPA dialect for
Derby or for mysql if i use it or it is automatic from the classpath ?
And if it is necessary, how i can make it ?
i have read that for mysql openJPA can have problems.




--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661981.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by "John D. Ament" <jo...@gmail.com>.
According to your code, line 45 is:

            out.println("
Servlet InserimentoServlet at " + request.getContextPath() + "
");

though it would be easier if you gist'd this since the lines don't
necessary match up correctly.  But that would imply that the request is
null at this time.  Can you gist it? I don't think you sent the full
servlet class (since it's however it's being called on line 84.)  Is it
possible you're not passing in the request object?


On Wed, Apr 3, 2013 at 10:51 AM, mauro2java2011 <ma...@gmail.com>wrote:

> yes into web-inf i have:
> beans.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://java.sun.com/xml/ns/javaee"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
> </beans>
>
> .....................................
> the servlet:
>
> -------------------
> package srv2;
>
> import ejb.GestoreEjb;
> import entita.Persona;
> import java.io.IOException;
> import java.io.PrintWriter;
> import java.util.List;
> import javax.inject.Inject;
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> /**
>  *
>  * @author spazio
>  */
> @WebServlet(name = "Servlet1", urlPatterns = {"/Servlet1"})
> public class Servlet1 extends HttpServlet {
> @Inject
> GestoreEjb miogestore;
>
>
>  protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
>             throws ServletException, IOException {
>         response.setContentType("text/html;charset=UTF-8");
>         PrintWriter out = response.getWriter();
>        try {
>
>             List<Persona> elencoPersone=
> this.miogestore.getElencoPersone();
>
>             /* TODO output your page here. You may use following sample
> code. */
>             out.println("<!DOCTYPE html>");
>             out.println("<html>");
>             out.println("<head>");
>             out.println("<title>Servlet ElencoPersoneServlet</title>");
>             out.println("</head>");
>             out.println("<body>");
>             out.println("
> Servlet ElencoPersoneServlet at " + request.getContextPath() + "
> ");
>            for (Persona p: elencoPersone)      {
>            out.println("id="+p.getId()+" nome="+p.getNome());
>
>            out.println("<br/>");
>
>            }
>
>             out.println("</body>");
>             out.println("</html>");
>         }catch (Exception e){
>         e.printStackTrace(out);
>         } finally {
>             out.close();
>         }
>     }
>
>
> ...................................................................................................................
>
> the servlet2
>
> package srv2;
>
> import ejb.GestoreEjb;
> import entita.Persona;
> import java.io.IOException;
> import java.io.PrintWriter;
> import javax.inject.Inject;
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> /**
>  *
>  * @author spazio
>  */
> @WebServlet(name = "Servlet2", urlPatterns = {"/Servlet2"})
> public class Servlet2 extends HttpServlet {
> @Inject
> GestoreEjb miogestore;
>
>
> protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
>             throws ServletException, IOException {
>         response.setContentType("text/html;charset=UTF-8");
>         PrintWriter out = response.getWriter();
>         try {
>
>             String nome = request.getParameter("nome");
>             Persona p = new Persona(nome);
>          this.miogestore.persist(p);
>
>
>
>             /* TODO output your page here. You may use following sample
> code. */
>             out.println("<!DOCTYPE html>");
>             out.println("<html>");
>             out.println("<head>");
>             out.println("<title>Servlet InserimentoServlet</title>");
>             out.println("</head>");
>             out.println("<body>");
>             out.println("
> Servlet InserimentoServlet at " + request.getContextPath() + "
> ");
>             out.println("inserimento eseguito");
>             out.println("<br/>");
>
>
>             out.println("</body>");
>             out.println("</html>");
>         } catch (Exception e) {
>             e.printStackTrace(out);
>         } finally {
>             out.close();
>         }
>     }
>
> -------------------------------------------------------------
>
> the index.jsp :
>
>
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
> <!DOCTYPE html>
> <html>
>     <head>
>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>         <title>JSP Page</title>
>     </head>
>     <body>
>         <form action="Servlet2">
>             <input type="text" name="nome" value="" />
>             <input type="submit" value="ok" /><input type="reset"
> value="reset" />
>         </form>
>          Elenco persone nel database <Servlet1>
>     </body>
> </html>
>
>
> ----------------------------------------------------
>
> the ejb:
>
> package ejb;
>
> import entita.Persona;
> import java.util.List;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.ejb.Stateless;
> import javax.persistence.EntityManager;
> import javax.persistence.EntityManagerFactory;
> import javax.persistence.Persistence;
> import javax.persistence.PersistenceContext;
>
> /**
>  *
>  * @author spazio
>  */
> @Stateless
> public class GestoreEjb {
>     @PersistenceContext(unitName = "PrimoconDB_maurojeePU")
>     private EntityManager em;
>
>
>
>
>     public List<Persona> getElencoPersone() {
>         return em.createQuery("select p from Persona p").getResultList();
>
>     }
>
>     public void persist(Persona persona) {
>         em.persist(persona);
>     }
> }
>
> ..........................................
>
> the entity:
>
> package entita;
>
> import java.io.Serializable;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
>
> /**
>  *
>  * @author spazio
>  */
> @Entity
> public class Persona implements Serializable {
>     private static final long serialVersionUID = 1L;
>     @Id
>     @GeneratedValue(strategy = GenerationType.AUTO)
>     private Long id;
>
>     public Long getId() {
>         return id;
>     }
>
>     public void setId(Long id) {
>         this.id = id;
>     }
>
>     private String nome;
>
>     public Persona() {
>     }
>
>     public Persona(String nome) {
>         this.nome = nome;
>     }
>
>
>
>     @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 Persona)) {
>             return false;
>         }
>         Persona other = (Persona) 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 "entita.Persona[ id=" + id + " ]";
>     }
>
>     /**
>      * @return the nome
>      */
>     public String getNome() {
>         return nome;
>     }
>
>     /**
>      * @param nome the nome to set
>      */
>     public void setNome(String nome) {
>         this.nome = nome;
>     }
>
> }
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661960.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: web application not work with db mysql and derby

Posted by mauro2java2011 <ma...@gmail.com>.
yes into web-inf i have:
beans.xml 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

.....................................
the servlet:

-------------------
package srv2;

import ejb.GestoreEjb;
import entita.Persona;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author spazio
 */
@WebServlet(name = "Servlet1", urlPatterns = {"/Servlet1"})
public class Servlet1 extends HttpServlet {
@Inject
GestoreEjb miogestore;


 protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
       try {
            
            List<Persona> elencoPersone= this.miogestore.getElencoPersone();
            
            /* TODO output your page here. You may use following sample
code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ElencoPersoneServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("
Servlet ElencoPersoneServlet at " + request.getContextPath() + "
");
           for (Persona p: elencoPersone)      {
           out.println("id="+p.getId()+" nome="+p.getNome());
           
           out.println("<br/>");
           
           }
            
            out.println("</body>");
            out.println("</html>");
        }catch (Exception e){
        e.printStackTrace(out);
        } finally {            
            out.close();
        }
    }

...................................................................................................................

the servlet2

package srv2;

import ejb.GestoreEjb;
import entita.Persona;
import java.io.IOException;
import java.io.PrintWriter;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author spazio
 */
@WebServlet(name = "Servlet2", urlPatterns = {"/Servlet2"})
public class Servlet2 extends HttpServlet {
@Inject
GestoreEjb miogestore;


protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            String nome = request.getParameter("nome");
            Persona p = new Persona(nome);
         this.miogestore.persist(p);



            /* TODO output your page here. You may use following sample
code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet InserimentoServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("
Servlet InserimentoServlet at " + request.getContextPath() + "
");
            out.println("inserimento eseguito");
            out.println("<br/>");
           
           
            out.println("</body>");
            out.println("</html>");
        } catch (Exception e) {
            e.printStackTrace(out);
        } finally {            
            out.close();
        }
    }

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

the index.jsp :


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="Servlet2">
            <input type="text" name="nome" value="" />
            <input type="submit" value="ok" /><input type="reset"
value="reset" />
        </form>
         Elenco persone nel database <Servlet1>  
    </body>
</html>


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

the ejb:

package ejb;

import entita.Persona;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

/**
 *
 * @author spazio
 */
@Stateless
public class GestoreEjb {
    @PersistenceContext(unitName = "PrimoconDB_maurojeePU")
    private EntityManager em;

  
 

    public List<Persona> getElencoPersone() {
        return em.createQuery("select p from Persona p").getResultList();

    }

    public void persist(Persona persona) {
        em.persist(persona);
    }
}

..........................................

the entity:

package entita;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author spazio
 */
@Entity
public class Persona implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    private String nome;

    public Persona() {
    }

    public Persona(String nome) {
        this.nome = nome;
    }
    
    

    @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 Persona)) {
            return false;
        }
        Persona other = (Persona) 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 "entita.Persona[ id=" + id + " ]";
    }

    /**
     * @return the nome
     */
    public String getNome() {
        return nome;
    }

    /**
     * @param nome the nome to set
     */
    public void setNome(String nome) {
        this.nome = nome;
    }
    
}





--
View this message in context: http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958p4661960.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: web application not work with db mysql and derby

Posted by "John D. Ament" <jo...@gmail.com>.
Since it's a null pointer in your servlet:

srv2.Servlet1.processRequest(Servlet1.java:45) at

We'd have to see your servlet.  Did you include a beans.xml in WEB-INF?


On Wed, Apr 3, 2013 at 10:12 AM, mauro2java2011 <ma...@gmail.com>wrote:

> i have write a simple web applciation with ejb and @Inject it into 2
> Servlet
> .
> But i get the following exception :
>
> java.lang.NullPointerException at
> srv2.Servlet1.processRequest(Servlet1.java:45) at
> srv2.Servlet1.doGet(Servlet1.java:84) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at
>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
> at
>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45) at
>
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at
>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at
>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at
>
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
> at
>
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
> at
>
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
> at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:662)
>
>
> whi?
> what it is the error?
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/web-application-not-work-with-db-mysql-and-derby-tp4661958.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>