IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

Probléme d'utilisation de Struts et Hibernate ensemble.


Sujet :

Struts 1 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Par défaut Probléme d'utilisation de Struts et Hibernate ensemble.
    Bonjour, mon pobléme est plus que bizzare je voudrai développer 1 application utilisant struts et hibernate, j'ai donc suivi quelque tutoriaux et ca marche pour struts et hibernate indépendament mais quand je veu combiner les deux, ca devient impossible.
    J'ai pourtant suivi et apré télécharger le code pour ce tutorial :

    http://www.laliluna.de/struts-hibern...torial-en.html

    J'ai bien sur importer toute les bilbiothéques nécessaires( puisque ca marche séparement) .
    Voila donc quand je teste hibernate ca marcher dans cet exemple mais quand j'ouvre la premiére page et que je veut afficher la liste des livres il m'affiche le messge suivant :

    Etat HTTP 500 -
    description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
    exception

    javax.servlet.ServletException: L'exécution de la servlet a lancé une exception

    cause mère
    java.lang.NoClassDefFoundError: org/hibernate/Session
    de.laliluna.library.bl.LibraryManager.getAllBooks(LibraryManager.java:40)
    de.laliluna.library.struts.action.BookListAction.execute(BookListAction.java:45)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    Désolé si le post est long mais c'est que je suis bloquer depuis 1 semaine sur ca et j'ai tout éssayer mais ca ne marche jamais.
    Alors je voit pas comment résoudre ca.
    Merci pour votre aide.

  2. #2
    Membre averti
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Par défaut
    S'il vous plai est ce que quelqu'un aurait une réponse?

  3. #3
    Membre chevronné

    Profil pro
    Inscrit en
    Mars 2007
    Messages
    392
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 392
    Par défaut
    as-tu des erreurs au démarrage de ton serveur d'application?

  4. #4
    Membre Expert Avatar de willoi
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    1 355
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 355
    Par défaut
    Montre voir cette classe :
    de.laliluna.library.bl.LibraryManager

  5. #5
    Membre Expert
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Par défaut
    java.lang.NoClassDefFoundError: org/hibernate/Session
    Le message d'erreur est clair : tu n'as pas déployé la librairie Hibernate.
    Quand tu dis que ça marche séparément, tu es sûr que c'est dans le contexte de ton serveur d'appli que tu as testé ? Pas dans ton EDI ?

    La clairement le jar n'est pas dans le WEB-INF/lib de ta webapp ...

  6. #6
    Membre averti
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Par défaut
    Merci pour votre réponse, j'avoue que j'ai bien importé le jar depuis dans mon projet, et effectivement ca marche sépparement (j'arrive a ajouter dans la base de données et a afficher meme avec hibernate),

    Sinon pour le code de la classe comme je l'ai déja dit ca vient du tutorial :



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
     
    /*
     * Created on 25.11.2004 by HS
     * 
     */
    package de.laliluna.library.bl;
     
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;
     
    import org.hibernate.Session;
    import org.hibernate.Transaction;
     
    import de.laliluna.library.Book;
    import de.laliluna.library.Customer;
    import de.laliluna.library.HibernateSessionFactory;
     
    /**
     * @author HS
     * 
     * 
     */
    public class LibraryManager {
     
    	/**
             * get all books from the database
             * 
             * @return Array of BookValue
             */
    	public Book[] getAllBooks() {
    		/* will hold the books we are going to return later */
    		List books = new ArrayList();
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		List tmpBooks = session.createQuery(
    				"select b from Book as b order by b.author, b.title").list();
    		for (Iterator iter = tmpBooks.iterator(); iter.hasNext();) {
    			books.add((Book) iter.next());
    		}
    		tx.commit();
     
    		return (Book[]) books.toArray(new Book[0]);
    	}
     
    	/**
             * get book by primary key
             * 
             * @param primaryKey
             * @return a Book or null
             */
    	public Book getBookByPrimaryKey(Integer primaryKey) {
    		/* holds our return value */
    		Book book = null;
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		book = (Book) session.get(Book.class, primaryKey);
    		tx.commit();
    		return book;
    	}
     
    	/**
             * sets the book as borrowed to the user specified in the database
             * 
             * @param primaryKey
             * @param userPrimaryKey
             */
    	public void borrowBook(Integer primaryKey, Integer customerPrimaryKey) {
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		Book book = (Book) session.get(Book.class, primaryKey);
    		// only if borrowing of the book is allowed
    		if (book.getBorrowallowed()) {
    			Customer customer = (Customer) session.get(Customer.class,
    					customerPrimaryKey);
    			if (book != null && customer != null)
    				book.setCustomer(customer);
    		}
     
    		tx.commit();
    	}
     
    	/**
             * customer returns a book, relation in the db between customer and book is
             * deleted
             * 
             * @param primaryKey
             */
    	public void returnBook(Integer primaryKey) {
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		Book book = (Book) session.get(Book.class, primaryKey);
     
    		if (book != null) {
    			// session.get returns null when no entry is found
    			Customer customer = book.getCustomer();
    			if (customer != null) {
    				customer.getBooks().remove(book);
    				book.setCustomer(null);
    			}
    		}
    		tx.commit();
    	}
     
    	/**
             * updates/creates a book
             * 
             * @param bookValue
             */
    	public void saveBook(Book bookValue) {
     
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		Book book;
    		if (bookValue.getId() != null && bookValue.getId().intValue() != 0) { // [laliluna]
    			// 04.12.2004
    			// load
    			// book
    			// from
    			// DB
    			book = (Book) session.get(Book.class, bookValue.getId());
    			if (book != null) {
    				book.setAuthor(bookValue.getAuthor());
    				book.setTitle(bookValue.getTitle());
    				book.setBorrowallowed(bookValue.getBorrowallowed());
    				session.update(book);
    			}
    		} else // [laliluna] 04.12.2004 create new book
    		{
    			book = new Book();
    			book.setAuthor(bookValue.getAuthor());
    			book.setTitle(bookValue.getTitle());
    			book.setBorrowallowed(bookValue.getBorrowallowed());
    			session.save(book);
    		}
    		tx.commit();
    	}
     
    	/**
             * deletes a book
             * 
             * @param primaryKey
             */
    	public void removeBookByPrimaryKey(Integer primaryKey) {
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
    		tx = session.beginTransaction();
    		Book book = (Book) session.get(Book.class, primaryKey);
    		if (book != null)
    			if (book.getCustomer() != null)
    				book.getCustomer().getBooks().remove(book);
    		session.delete(book);
    		tx.commit();
    	}
     
    	/**
             * returns all customers from the db
             * 
             * @return
             */
     
    	public Customer[] getAllCustomers() {
    		/* will hold the books we are going to return later */
    		List customers = new ArrayList();
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		List tmpCustomer = session.createQuery(
    				"select c from Customer as c order by c.lastname").list();
    		for (Iterator iter = tmpCustomer.iterator(); iter.hasNext();) {
    			customers.add((Customer) iter.next());
    		}
    		tx.commit();
    		return (Customer[]) customers.toArray(new Customer[0]);
    	}
     
    	/**
             * gets a customer from the db
             * 
             * @param primaryKey
             * @return the customer class or null, when no customer is found
             */
    	public Customer getCustomerByPrimaryKey(Integer primaryKey) {
    		/* holds our return value */
    		Customer customer = null;
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		customer = (Customer) session.get(Customer.class, primaryKey);
    		tx.commit();
     
    		return customer;
    	}
     
    	/**
             * saves the customers to the db
             * 
             * @param customer
             */
    	public void saveCustomer(Customer customer) {
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
    		tx = session.beginTransaction();
    		if (customer.getId() == null || customer.getId().intValue() == 0) // [laliluna]
    			// 06.12.2004
    			// create
    			// customer
    			session.save(customer);
    		else {
    			Customer toBeUpdated = (Customer) session.get(Customer.class,
    					customer.getId());
    			toBeUpdated.setAge(customer.getAge());
    			toBeUpdated.setLastname(customer.getLastname());
    			toBeUpdated.setFirstname(customer.getFirstname());
    			session.update(toBeUpdated);
    		}
    		tx.commit();
    	}
     
    	/**
             * deletes a customer from the database
             * 
             * @param primaryKey
             */
    	public void removeCustomerByPrimaryKey(Integer primaryKey) {
    		/* a Hibernate session */
    		Session session = null;
    		/* we always need a transaction */
    		Transaction tx = null;
     
    		/* get session of the current thread */
    		session = HibernateSessionFactory.currentSession();
     
    		tx = session.beginTransaction();
    		Customer customer = (Customer) session.get(Customer.class, primaryKey);
    		if (customer != null) {
    			Set books = customer.getBooks();
    			for (Iterator iter = books.iterator(); iter.hasNext();) {
    				Book element = (Book) iter.next();
    				element.setCustomer(null);
    			}
     
    			session.delete(customer);
    		}
    		tx.commit();
    	}
     
    }
    Quand aux erreurs j'avoue qu'il y'en a 2 concernant d'autres projet mais cella il n'est pas préciser le nom du projet :


    GRAVE: StandardWrapper.Throwable
    java.lang.NoClassDefFoundError: org/hibernate/HibernateException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:231)
    at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1142)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3880)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4141)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(StandardService.java:450)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

    Merci pour votre aide ca me fait perdre un temps fou.

Discussions similaires

  1. Problème DWR 3 + Spring + Struts 2 + Hibernate 3
    Par maili20 dans le forum Autres
    Réponses: 2
    Dernier message: 15/05/2009, 17h28
  2. problème de liaison Struts avec Hibernate
    Par barchoui dans le forum Struts 1
    Réponses: 3
    Dernier message: 01/12/2008, 15h06
  3. [Struts Menu][Tiles] Problème d'utilisation
    Par newmar dans le forum Struts 1
    Réponses: 4
    Dernier message: 12/05/2008, 11h22
  4. [Struts-Layout] Problème d'utilisation du Datagrid
    Par nabil148911 dans le forum Struts 1
    Réponses: 12
    Dernier message: 30/07/2007, 12h18
  5. [JVM_Bind:8080]Problèmes utilisation Eclipse/Struts/Tomcat
    Par _Maud_ dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 30/01/2006, 19h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo