jpa - (JAVA EE) Method not working without throwing any error -


i'm developping airline management web application java ee, ejb & jpa (eclipselink)

i'm having trouble when i'm calling method in service layer servlet : method don't expected without having error.

the method addpassengertoflight trying add passenger passengers list have in flight entity manytomany relationship.

this structure of priject.

this flight , passenger entities whitout getters , setters:

flight:

public class flight implements serializable {       @id     @generatedvalue( strategy = generationtype.auto )     private integer         id;      @enumerated( enumtype.string )     private cities          depart;      @enumerated( enumtype.string )     private cities          destination;      private string          prix;      @temporal( temporaltype.timestamp )     private date            date;      @manytomany( cascade = { cascadetype.merge, cascadetype.persist, cascadetype.refresh } )     @jointable( name = "f_p_join", joincolumns = @joincolumn( name = "flight_fk" ), inversejoincolumns = @joincolumn( name = "passenger_fk" ) )     private list<passenger> passengers;      @onetoone( )     @joincolumn( name = "airplane_fk" )     private plane           airplane;      @onetoone( )     @joincolumn( name = "pilot_fk" )     private pilot           pilot; } 

passenger:

public class passenger implements serializable {       @id     @generatedvalue( strategy = generationtype.auto )     private integer      id;      private string       nom;      private string       prenom;      private string       adresse;      private string       telephone;      private string       email;      @enumerated( enumtype.string )     private flightclass  flightclass;      @manytomany( mappedby = "passengers" )     private list<flight> flights; } 

the passenerservice have method :

public class passengerservice {      private static final string champ_flight_id    = "flightid";     private static final string champ_passenger_id = "passengerid";      private string              resultat;     private map<string, string> erreurs            = new hashmap<string, string>();     private passengerdao        passengerdao;     private flightdao           flightdao;     private pilotdao            pilotdao;     private planedao            planedao;      public map<string, string> geterreurs() {         return erreurs;     }      public string getresultat() {         return resultat;     }      public passengerservice( passengerdao passengerdao, flightdao flightdao, pilotdao pilotdao, planedao planedao ) {         this.passengerdao = passengerdao;         this.flightdao = flightdao;         this.pilotdao = pilotdao;         this.planedao = planedao;     }      public passenger createpassenger( httpservletrequest request ) {         //the createpassenger code     }      public list<passenger> getallpassengers() {         //the getallpassengers code     }      public void addpassengertoflight( httpservletrequest request ) {         flightservice flightservice = new flightservice( flightdao, planedao, pilotdao );          string passengerid = request.getparameter( champ_passenger_id );         string flightid = request.getparameter( champ_flight_id );          passenger passenger = getpassengerbyid( passengerid );         flight flight = flightservice.getflightbyid( flightid );          list<passenger> plist = flight.getpassengers();         plist.add( passenger );         flight.setpassengers( plist );          passenger.getflights().add( flight );      }      public passenger getpassengerbyid( string passengerid ) {         passenger passenger = passengerdao.getpassengerbyid( passengerid );         return passenger;     }      public void removepassenger( passenger passenger ) {        //the removepassenger code      }   } 

and servlet addpassengertoflight

@webservlet( "/addpassengertoflight" ) public class addpassengertoflight extends httpservlet {      private static final string vue_redirect     = "/airline/passengerlist";      private static final long   serialversionuid = 1l;      @ejb     flightdao                   flightdao;      @ejb     pilotdao                    pilotdao;      @ejb     planedao                    planedao;      @ejb     passengerdao                passengerdao;       protected void doget( httpservletrequest request, httpservletresponse response ) throws servletexception,             ioexception {         flightservice flightservice = new flightservice( flightdao, planedao, pilotdao );         passengerservice passengerservice = new passengerservice( passengerdao, flightdao, pilotdao, planedao );          list<flight> flights = flightservice.getallflights();         list<passenger> passengers = passengerservice.getallpassengers();         request.setattribute( "flights", flights );         request.setattribute( "passengers", passengers );         this.getservletcontext().getrequestdispatcher( vue ).forward( request, response );     }       protected void dopost( httpservletrequest request, httpservletresponse response ) throws servletexception,             ioexception {         passengerservice passengerservice = new passengerservice( passengerdao, flightdao, pilotdao, planedao );          passengerservice.addpassengertoflight( request );         response.sendredirect( vue_redirect );      }  } 

and form addpassengertoflight (the jsp file)

<div class="container">         <h2>adding passenger flight</h2>         <br/><br/>         <form method="post" action="addpassengertoflight">             <div class="form-group">                 <h4>flight :</h4>                 <select name="flightid" class="selectpicker" data-live-search="true" data-width="100%">                     <c:foreach items="${flights}" var="flight">                         <option value="${flight.id}">                             <c:out value="${flight.depart}" /> <c:out value="${flight.destination}" /> @ <c:out value="${flight.date}" />                         </option>                     </c:foreach>                 </select>             </div>               <div class="form-group">                 <h4>passenger :</h4>                 <select name="passengerid" class="selectpicker" data-live-search="true" data-width="100%">                     <c:foreach items="${passengers}" var="passenger">                         <option value="${passenger.id}"><c:out value="${passenger.nom}" /></option>                     </c:foreach>                 </select>             </div>              <button type="submit" class="btn btn-default">submit</button>          </form>     </div> 

when click button submit of addpassengertoflight im redirected passengerlist nothing happens between 2 entities (flight , passenger) , have no error.

can figure out doing wrong here ?

i believe problem passengerservice class plain java class (i explain, not ejb service)... thus, when make association between passanger , flight in class, there no jta transaction running , entities in detach mode; so, changes on them never persisted @ database.

you can try see if i'm correct... make service ejb class , inject required daos through @ejb annotation, servlet inject new ejb , invoke method: addpassengertoflight( httpservletrequest request ) ...


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -