{"id":74343,"date":"2019-07-11T11:00:17","date_gmt":"2019-07-11T08:00:17","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=74343"},"modified":"2019-07-11T12:39:18","modified_gmt":"2019-07-11T09:39:18","slug":"jax-ws-hibernate-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/","title":{"rendered":"JAX-WS Hibernate Example"},"content":{"rendered":"<p>In this example,  we feature a comprehensive article on JAX-WS Hibernate. We will demonstrate&nbsp;how to create a SOAP-based web service that uses Hibernate to read data from a database.<\/p>\n<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>Java API for XML Web Services (JAX-WS) is a technology for developing SOAP-based web services and clients. The API includes annotations for defining web service endpoints, service implementation beans, and other related artifacts. JAX-WS uses Java API for XML Binding (JAXB) to&nbsp;bind Java objects to XML schemas that are used in building SOAP messages.<\/p>\n<p>Java Persistence API, or JPA for short, is a specification used for mapping Java objects to database tables and for managing entities in a relational database.&nbsp; It provides annotations for object-relational mapping (ORM), and an entity manager for handling entities within a persistence context. Hibernate is a JPA provider that implements the interfaces defined in the JPA specification.  <\/p>\n<p>In this example, we will demonstrate how to create a JAX-WS web<br \/>\nservice that uses Hibernate to retrieve data from a relational database.<\/p>\n<h3 class=\"wp-block-heading\">1.1 Tools Used in this Example<\/h3>\n<ul class=\"wp-block-list\">\n<li>Eclipse IDE for Enterprise Java Developers Version: 2019-03 (4.11.0)<\/li>\n<li>Spring Tools 4 \u2013 for Spring Boot&nbsp;<\/li>\n<li>SoapUI 5.5.0       <\/li>\n<\/ul>\n<p>Spring Tools 4 for Spring Boot is a set of plugins for Eclipse that support building and running Spring Boot applications. You can add Spring Tools 4 to your existing Eclipse installation by going to the Eclipse Marketplace and searching for \u201cSpring Tools 4\u201d.<\/p>\n<p>You can download SoapUI at  <a href=\"https:\/\/www.soapui.org\/downloads\/soapui.html\">https:\/\/www.soapui.org\/downloads\/<\/a><a rel=\"noreferrer noopener\" aria-label=\"soapui.html (opens in a new tab)\" href=\"https:\/\/www.soapui.org\/downloads\/soapui.html\" target=\"_blank\">soapui.html<\/a>. <\/p>\n<h2 class=\"wp-block-heading\">2. JAX-WS Hibernate Example<\/h2>\n<p>In this example, we will build is a simple web service that returns a list of events for the specified artist. The service has one method; <code>getEventInfo<\/code>. The method executes a transaction against a database to retrieve the list of events. We will create the web service using bottom-up web service development.<\/p>\n<h3 class=\"wp-block-heading\">2.1 Create the Spring Boot Project<\/h3>\n<p>Let\u2019s start by creating a Spring Boot project. In the&nbsp;<em>New Project \u2013 Select a Wizard<\/em>&nbsp;dialog box, expand Spring Boot and select Spring Starter Project. Click \u201cNext\u201d.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2018\/07\/project_wizard-wm.jpg\" alt=\"JAX-WS Hibernate - Select a Wizard\"\/><figcaption> Select a Wizard<\/figcaption><\/figure>\n<\/div>\n<p>In the&nbsp;<em>New Spring Starter Project<\/em>&nbsp;dialog box, enter a name for the project. Also, enter the group, artifact and package information. Accept all the other default values. Click \u201cNext\u201d. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"567\" height=\"787\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/spring-starter-wm.jpg\" alt=\"JAX-WS Hibernate - Spring Starter Project\" class=\"wp-image-74607\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/spring-starter-wm.jpg 567w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/spring-starter-wm-216x300.jpg 216w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><figcaption>New Spring Starter Project<\/figcaption><\/figure>\n<\/div>\n<p>In the&nbsp;<em>New Spring Starter Project Dependencies<\/em>&nbsp;dialog box, select Spring Boot Version 2.1.6. Also, select the Spring Data JPA and H2 Database dependencies. Click \u201cFinish\u201d. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"567\" height=\"770\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/project-depend-wm.jpg\" alt=\"\" class=\"wp-image-74608\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/project-depend-wm.jpg 567w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/project-depend-wm-221x300.jpg 221w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><figcaption>Spring Starter Project Dependencies<\/figcaption><\/figure>\n<\/div>\n<p>The JPA dependency will add Spring Data JPA and Hibernate capabilities to the project.&nbsp;We will be using an H2 embedded in-memory database. <\/p>\n<h3 class=\"wp-block-heading\">2.2 Add JAX-WS Dependencies<\/h3>\n<p>We will use Apache CXF as our JAX-WS web service stack.&nbsp;Open the&nbsp;<em>pom.xml<\/em>&nbsp;file and add the <em>cxf-spring-boot-starter-jaxws<\/em> dependency just below the&nbsp;<em>spring-boot-starter-data-jpa<\/em>&nbsp;dependency:<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false; highlight:[28,29,30,31,32]\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;parent&gt;\n\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t&lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n\t\t&lt;version&gt;2.1.6.RELEASE&lt;\/version&gt;\n\t\t&lt;relativePath \/&gt; &lt;!-- lookup parent from repository --&gt;\n\t&lt;\/parent&gt;\n\t&lt;groupId&gt;com.javacodegeeks.examples&lt;\/groupId&gt;\n\t&lt;artifactId&gt;jax-ws-hibernate&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;name&gt;jax-ws-hibernate&lt;\/name&gt;\n\t&lt;description&gt;Example project for Spring Boot&lt;\/description&gt;\n\n\t&lt;properties&gt;\n\t\t&lt;java.version&gt;1.8&lt;\/java.version&gt;\n\t&lt;\/properties&gt;\n\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;\/artifactId&gt;\n\t\t&lt;\/dependency&gt;\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.apache.cxf&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;cxf-spring-boot-starter-jaxws&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;3.2.7&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;com.h2database&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;h2&lt;\/artifactId&gt;\n\t\t\t&lt;scope&gt;runtime&lt;\/scope&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n\n\t&lt;build&gt;\n\t\t&lt;plugins&gt;\n\t\t\t&lt;plugin&gt;\n\t\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t\t&lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\n\t\t\t&lt;\/plugin&gt;\n\t\t&lt;\/plugins&gt;\n\t&lt;\/build&gt;\n\n&lt;\/project&gt;\n\n<\/pre>\n<h3 class=\"wp-block-heading\">2.3 Create the JPA Entity Model <\/h3>\n<p>There are two entities in the entity model; Artist and Event. The Artist entity has an <em>id<\/em> and a <em>name<\/em> property. The Event entity has an <em>id<\/em>, a <em>venue<\/em>, and a <em>date<\/em> property. The Artist entity has a one-to-many relationship with the Event entity, as illustrated in the Entity Relationship diagram below.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"728\" height=\"231\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/1-to-many-wm-1.jpg\" alt=\"\" class=\"wp-image-74649\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/1-to-many-wm-1.jpg 728w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/1-to-many-wm-1-300x95.jpg 300w\" sizes=\"(max-width: 728px) 100vw, 728px\" \/><figcaption> One-to-Many Relationship<\/figcaption><\/figure>\n<p>The diagram above shows that the Artist entity is associated to zero or more Event entities.<\/p>\n<h4 class=\"wp-block-heading\">2.3.1 Create the Artist Entity Class<\/h4>\n<p>Create a package&nbsp;<code>com.javacodegeeks.examples.entities<\/code>&nbsp;and a class&nbsp;<code>Artist<\/code>&nbsp;with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Artist.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.entities;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport javax.persistence.CascadeType;\nimport javax.persistence.Column;\nimport javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.Id;\nimport javax.persistence.OneToMany;\n\n@Entity\npublic class Artist {\n\n\t@Id\n\t@GeneratedValue\n\tprivate int id;\n\t\n\t@Column(unique = true, nullable = false)\n\tprivate String name;\n\t\n\t@OneToMany(mappedBy=\"artist\",\n\t\t\t   cascade= {CascadeType.PERSIST, CascadeType.MERGE,\n\t\t\t\t\t\t CascadeType.DETACH, CascadeType.REFRESH})\n\tprivate List&lt;Event&gt; events;\n\t\n\tpublic Artist() {}\n\n\t\n\tpublic Artist(String name) {\n\t\tthis.name = name;\n\t}\n\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\n\tpublic List&lt;Event&gt; getEvents() {\n\t\treturn events;\n\t}\n\n\n\tpublic void setEvents(List&lt;Event&gt; events) {\n\t\tthis.events = events;\n\t}\n\n\n\tpublic void add(Event event) {\n\t\t\n\t\tif (events == null) {\n\t\t\tevents = new ArrayList&lt;&gt;();\n\t\t}\n\t\t\n\t\tevents.add(event);\n\t}\n}\n\n<\/pre>\n<p><em><strong>Note<\/strong>: You have will several errors at this point. They will be resolved in the next section of this example.<\/em><\/p>\n<p>There are several JPA annotations used in the Artist class. These annotations define the mapping between the entity model object and the database table and its columns. (Note that these annotations are from the&nbsp;<code>javax.persistence&nbsp;package<\/code>.)<\/p>\n<ul class=\"wp-block-list\">\n<li><strong><em>@Entity<\/em><\/strong>&nbsp;\u2013 This class-level annotation informs the JPA provider (Hibernate in our example) that this Java class should be persisted to a database table.<\/li>\n<li><strong><em>@Id<\/em><\/strong>&nbsp;\u2013 This field-level annotation  designates  the primary key of the entity and maps it to the primary key of the table.&nbsp;<\/li>\n<li><strong><em>@GeneratedValue<\/em><\/strong>&nbsp;\u2013 This annotation specifies how the primary key ID will be generated.&nbsp; In our example, we chose&nbsp;<em>GenerationType<\/em>.<em>AUTO,<\/em><strong><em>&nbsp;<\/em><\/strong>meaning that the JPA provider (Hibernate) will decide which strategy to employ based on the database dialect used. (The H2Dialect is used in this example.)&nbsp;<\/li>\n<li><strong><em>@Column<\/em><\/strong>&nbsp;\u2013 This field-level annotation is used to assign specific attributes to a property.&nbsp;We are specifying that the <em>name <\/em>property must be unique and that it cannot be null.<\/li>\n<li><strong><em>@OneToMany<\/em><\/strong> \u2013 This field-level annotation declares a one-to-many relationship between the Artist entity and Event entity. This annotation is placed on the <code>List&lt;Event&gt; events <\/code>property since there can be many Event entities associated with this one Artist. The <em>mappedBy<\/em> attribute references the property on the \u201cmany\u201d side of the relationship; the Event entity. (We will create the Event entity in the next section.) The cascade attribute identifies which entity lifecycle events (if any) should be propagated to the target of the association. For example, <em>CascadeType<\/em>.<em>PERSIST<\/em> states that any events in the list should be persisted into the persistence context when the Artist is persisted.<\/li>\n<\/ul>\n<p>There are two constructors defined for the Artist class. The <code>Artist(String name)<\/code> constructor is used for convenience. Consequently, we must explicitly define a no-argument constructor <code>Artist()<\/code>, which is required by the JPA Entity Manager. <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>We also added a helper method <code>add(Event event)<\/code>. The method will add the Artist to the Event entity when an event is added. This will set up the bi-directional link between Artist and Event.<\/p>\n<p>At this point, you will see the following error: <em>Event cannot be resolved to a type<\/em>. Let\u2019s fix that.<\/p>\n<h4 class=\"wp-block-heading\">2.3.2 Create the Event Entity Class<\/h4>\n<p>Hover your cursor over <code>Event <\/code>and select <em>Create Class \u2018Event\u2019<\/em>. Click the &#8220;Finish&#8221; button in the <em>New &#8211; Java Class <\/em>dialog box and add the following code to the Event class:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Event.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.entities;\n\nimport javax.persistence.CascadeType;\nimport javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.Id;\nimport javax.persistence.JoinColumn;\nimport javax.persistence.ManyToOne;\n\n@Entity\npublic class Event {\n\n\t@Id\n\t@GeneratedValue\n\tprivate int id;\n\t\n\tprivate String venue;\n\t\n\tprivate String date;\n\t\n\t@ManyToOne(cascade= {CascadeType.PERSIST, CascadeType.MERGE,\n\t\t\t CascadeType.DETACH, CascadeType.REFRESH})\n\t@JoinColumn(name=\"artist_id\")\n\tprivate Artist artist;\n\t\n\tpublic Event() {}\n\n\tpublic Event(String venue, String date, Artist artist) {\n\t\tthis.venue = venue;\n\t\tthis.date = date;\n\t\tthis.artist = artist;\n\t}\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic String getVenue() {\n\t\treturn venue;\n\t}\n\n\tpublic void setVenue(String venue) {\n\t\tthis.venue = venue;\n\t}\n\n\tpublic String getDate() {\n\t\treturn date;\n\t}\n\n\tpublic void setDate(String date) {\n\t\tthis.date = date;\n\t}\n\n\tpublic Artist getArtist() {\n\t\treturn artist;\n\t}\n\n\tpublic void setArtist(Artist artist) {\n\t\tthis.artist = artist;\n\t}\n\t\n}\n\n<\/pre>\n<p>The Event class is also decorated with the <code>@Entity<\/code> annotation. It has an <code>id <\/code>property for its primary key and two string properties for the venue name and the event date. It also has an <code>Artist <\/code>property.<\/p>\n<p>The <code>@ManyToOne<\/code> field-level annotation specifies the relationship between the Event entity and the Artist entity. It is placed on the <code>Artist artist<\/code> property as there can be many Events to one Artist.<\/p>\n<p>The <code>@JoinColumn<\/code> annotation specifies the column name in the Event table that will used to associate the Event to the Artist. (This will become the foreign key to the Artist table.)<\/p>\n<h3 class=\"wp-block-heading\">2.4 Create the Data Loader Class<\/h3>\n<p>We can use Hibernate to create some sample data at startup.&nbsp; Create a package&nbsp;<code>com.javacodegeeks.examples.bootstrap<\/code>&nbsp;and class&nbsp;<code>DataLoader<\/code>&nbsp;that implements&nbsp;<code>ApplicationListener&lt;ContextRefreshedEvent&gt;<\/code>&nbsp;: <\/p>\n<p><span style=\"text-decoration: underline\"><em>DataLoader.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.bootstrap;\n\nimport javax.persistence.EntityManager;\nimport javax.persistence.EntityManagerFactory;\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.ApplicationListener;\nimport org.springframework.context.event.ContextRefreshedEvent;\nimport org.springframework.stereotype.Component;\n\nimport com.javacodegeeks.examples.entities.Artist;\nimport com.javacodegeeks.examples.entities.Event;\n\n@Component\npublic class DataLoader implements ApplicationListener&lt;ContextRefreshedEvent&gt; {\n\n\t@Autowired\n\tprivate EntityManagerFactory entityManagerFactory;\n\n\t@Override\n\tpublic void onApplicationEvent(ContextRefreshedEvent event) {\n\t\tEntityManager entityManager = entityManagerFactory.createEntityManager();\n\t\t\n\t\tentityManager.getTransaction().begin();\n\t\t\n\t\tArtist artist = new Artist(\"The Who\");\n\t\t\n\t\tEvent Event1 = new Event(\"Wembley Stadium\", \"July 6, 2019\", artist);\n\t\tEvent Event2 = new Event(\"Hollywood Bowl\", \"October 28, 2019\", artist);\n\t\t\n\t\tartist.add(Event1);\n\t\tartist.add(Event2);\n\n\t\tentityManager.persist(artist);\n\n\t\tentityManager.getTransaction().commit();\n\t\t\n\t\n\t\tentityManager.getTransaction().begin();\n\t\t\n\t\tArtist artist2 = new Artist(\"The Rolling Stones\");\n\t\t\n\t\tEvent Event3 = new Event(\"Madison Square Garden\", \"September 12, 2019\", artist2);\t\t\n\t\tEvent Event4 = new Event(\"Dodger Stadium\", \"November 25, 2019\", artist2);\n\t\t\n\t\tartist2.add(Event3);\n\t\tartist2.add(Event4);\n\t\t\n\t\tentityManager.persist(artist2);\n\t\t\n\t\tentityManager.getTransaction().commit();\n\t}\n\n}\n\n<\/pre>\n<p>The <code>EntityManagerFactory <\/code>(used to create an <code>EntityManager<\/code>) is injected into the class using the <code>@Autowired<\/code> annotation. An<code>EntityManager <\/code>is used to create and delete entity instances and to find entities by their primary keys. It can also be used create and run queries. If the <code>EntityManager <\/code>is managed by the application, (as is the case here), it is also used to manage the lifecycle of entity instances through transaction management. <\/p>\n<p>The <code>DataLoader <\/code>class listens for the&nbsp;<code>ContextRefreshedEvent<\/code>&nbsp;that gets raised when the&nbsp;<code>ApplicationContext<\/code>&nbsp;is initialized or refreshed. It implements the&nbsp;<code>onApplicationEvent<\/code>&nbsp;method, which adds a couple of artists and their associated events to persistence context. Notice that the <code>EntityManager <\/code>is used to start and commit the transactions. Also notice that we only need to persist the <code>Artist <\/code>instance. The Event instances will be persisted automatically, thanks to <em>CascadeType<\/em>.<em>PERSIST<\/em> directive and our helper method.<\/p>\n<p>The <code>DataLoader <\/code>class is decorated with&nbsp;<code>@Component<\/code>&nbsp;to register it in the application context.<\/p>\n<h3 class=\"wp-block-heading\">2.5 Enable and Run the H2 Console<\/h3>\n<p>Spring Boot will automatically configure an H2 in-memory database if it finds the H2 related JAR files in the application\u2019s classpath. It will use the following default values unless otherwise specified in the <em>application.properties<\/em> file.<\/p>\n<pre class=\"brush:bash\">spring.datasource.url=jdbc:h2:mem:testdb\nspring.datasource.driverClassName=org.h2.Driver\nspring.datasource.username=sa\nspring.datasource.password=\nspring.jpa.database-platform=org.hibernate.dialect.H2Dialect\n\n<\/pre>\n<p>H2 comes with GUI console that can be used to view tables or run SQL queries. To enable it, add the following entry in <em>application.properties<\/em> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>application.properties<\/em><\/span><\/p>\n<pre class=\"brush:bash\">spring.h2.console.enabled=true\n<\/pre>\n<p>Start the application by right-clicking the project in Project Explorer and selecting&nbsp;<em>Run As &gt; Spring Boot App.<\/em> You can access the H2 console at the following URL: <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/localhost:8080\/h2-console\" target=\"_blank\">http:\/\/localhost:8080\/h2-console<\/a>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"516\" height=\"632\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-wm.jpg\" alt=\"\" class=\"wp-image-74634\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-wm.jpg 516w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-wm-245x300.jpg 245w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><figcaption>H2 Login Screen<\/figcaption><\/figure>\n<\/div>\n<p>Ensure the JDBC URL is <em>jdbc:h2:mem:testdb<\/em> and click the <em>Connect <\/em>button. You will see that the tables were created with the expected columns. Run an SQL query to view the data that was created at startup.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"600\" height=\"499\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-select-wm.jpg\" alt=\"\" class=\"wp-image-74635\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-select-wm.jpg 600w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/h2-select-wm-300x250.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>H2 Console<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">2.6 Create the Data Transfer Objects <\/h3>\n<p> We will create two Data Transfer Objects to transfer the request and response payloads. <\/p>\n<h4 class=\"wp-block-heading\">2.6.1 Create the Event Request<\/h4>\n<p>Create a package&nbsp;<code>com.javacodegeeks.examples.dto<\/code>&nbsp;and a class&nbsp;<code>EventRequest<\/code> with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>EventRequest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.dto;\n\nimport javax.xml.bind.annotation.XmlAccessType;\nimport javax.xml.bind.annotation.XmlAccessorType;\nimport javax.xml.bind.annotation.XmlElement;\nimport javax.xml.bind.annotation.XmlType;\n\n@XmlType(name = \"EventRequest\")\n@XmlAccessorType(XmlAccessType.FIELD)\npublic class EventRequest {\n\n\t@XmlElement(required = true)\n\tprivate String artistName;\n\n\tpublic String getArtistName() {\n\t\treturn artistName;\n\t}\n\n\tpublic void setArtistName(String artistName) {\n\t\tthis.artistName = artistName;\n\t}\n}\n<\/pre>\n<p><code>@XmlType<\/code> is a JAXB annotation that maps the <code>EventRequest<\/code> class to an XML schema type. The XML schema is used to generate the XML in the SOAP message. <code>EventRequest <\/code>will appear as a complex type in the WSDL file. <\/p>\n<p>The <code>EventRequest <\/code>class defines a string property called <code>artistName<\/code> along with its associated setter and getter. The <code>@XmlAccessorType(XmlAccessType.FIELD)<\/code> annotation will cause all non-static and non transient fields in the class to be automatically bound to the XML schema. We apply the <code>@XmlElement<\/code> annotation to the <em>artistName <\/em>field so that we can set its attribute as <em>required<\/em>.<\/p>\n<h4 class=\"wp-block-heading\">2.6.2 Create the Event Response<\/h4>\n<p>Create a class&nbsp;<code>EventResponse<\/code> in the <code>com.javacodegeeks.examples.dto<\/code> package&nbsp;with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>EventResponse.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.dto;\n\nimport javax.xml.bind.annotation.XmlType;\n\nimport com.javacodegeeks.examples.entities.Artist;\n\n@XmlType(name = \"EventResponse\")\npublic class EventResponse {\n\n\tprivate Artist artist;\n\n\tpublic Artist getArtist() {\n\t\treturn artist;\n\t}\n\n\tpublic void setArtist(Artist artist) {\n\t\tthis.artist = artist;\n\t}\n}\n<\/pre>\n<p>The <code>EventResponse<\/code> class is also decorated with the <code>@XmlType<\/code> annotation. The class contains the Artist object that will be returned in the response payload. Note that the list of events will also be returned in the response as they are part of the Artist entity.<\/p>\n<h3 class=\"wp-block-heading\">2.7  Update the Event Class<\/h3>\n<p>Since we have declared <code>Artist <\/code>as a property of the <code>Event <\/code>class, we need to make some changes to exclude it from the XML schema. If this is not corrected, we will get a marshalling error when the SOAP response is generated, due to a cycle in the object graph. (The Artist object has Event objects which in turn have Artist objects, you get the idea.) Open the Event class and add the highlighted code.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Event.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[13,21,24]; wrap-lines:false\">package com.javacodegeeks.examples.entities;\n\nimport javax.persistence.CascadeType;\nimport javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.Id;\nimport javax.persistence.JoinColumn;\nimport javax.persistence.ManyToOne;\nimport javax.xml.bind.annotation.XmlAccessType;\nimport javax.xml.bind.annotation.XmlAccessorType;\nimport javax.xml.bind.annotation.XmlElement;\n\n@XmlAccessorType(XmlAccessType.NONE)\n@Entity\npublic class Event {\n\n\t@Id\n\t@GeneratedValue\n\tprivate int id;\n\t\n\t@XmlElement\n\tprivate String venue;\n\t\n\t@XmlElement\n\tprivate String date;\n\t\n\t@ManyToOne(cascade= {CascadeType.PERSIST, CascadeType.MERGE,\n\t\t\t CascadeType.DETACH, CascadeType.REFRESH})\n\t@JoinColumn(name=\"artist_id\")\n\tprivate Artist artist;\n\t\n\tpublic Event() {}\n\n\tpublic Event(String venue, String date, Artist artist) {\n\t\tthis.venue = venue;\n\t\tthis.date = date;\n\t\tthis.artist = artist;\n\t}\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic String getVenue() {\n\t\treturn venue;\n\t}\n\n\tpublic void setVenue(String venue) {\n\t\tthis.venue = venue;\n\t}\n\n\tpublic String getDate() {\n\t\treturn date;\n\t}\n\n\tpublic void setDate(String date) {\n\t\tthis.date = date;\n\t}\n\n\tpublic Artist getArtist() {\n\t\treturn artist;\n\t}\n\n\tpublic void setArtist(Artist artist) {\n\t\tthis.artist = artist;\n\t}\n\t\n}\n\n<\/pre>\n<p>The <code>@XmlAccessorType(XmlAccessType.NONE<\/code><em>)<\/em> annotation blocks the properties of the class from being bound to the XML schema unless they are explicitly mapped. We apply the <code>@XmlElement<\/code> annotation to the <em>venue<\/em> and <em>date<\/em> properties to explicitly map them to the schema.<\/p>\n<h3 class=\"wp-block-heading\">2.8 Create the Service Endpoint Interface<\/h3>\n<p>Create a package&nbsp;<code>com.javacodegeeks.examples.service<\/code>&nbsp;and an interface <code>EventService <\/code>with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>EventService.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.service;\n\nimport javax.jws.WebService;\n\nimport com.javacodegeeks.examples.dto.EventRequest;\nimport com.javacodegeeks.examples.dto.EventResponse;\n\n@WebService(name = \"EventService\")\npublic interface EventService {\n\n\tpublic EventResponse getEventInfo(@XmlElement(required=true) EventRequest request);\n}\n\n<\/pre>\n<p>The&nbsp;<code>@WebService<\/code>&nbsp;annotation marks this interface as a service endpoint interface. The name attribute is optional. All public methods defined in the interface will be exposed to the client as operations, although you can use the&nbsp;<code>@WebMethod<\/code>&nbsp;annotation to specify attributes, such as specifying the operation\u2019s name in the WSDL file. The interface defines one method, <code>getEventInfo<\/code>, that accepts <code>EventRequest <\/code>as a parameter and returns an <code>EventResponse<\/code>. We set <code>EventRequest<\/code> as a required element of the<code>getEventInfo <\/code>complex type (in the XML schema) with the <code>@XmlElement(required=true)<\/code> annotation. <\/p>\n<h3 class=\"wp-block-heading\">2.9 Create the Service Endpoint Implementation<\/h3>\n<p>Create a class&nbsp;<code>EventServiceImpl <\/code>that implements the <code>EventService <\/code>interface in the <code>com.javacodegeeks.examples.service<\/code> package with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>EventServiceImpl.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.service;\n\nimport javax.persistence.EntityManager;\nimport javax.persistence.EntityManagerFactory;\nimport javax.persistence.Query;\n\nimport org.springframework.stereotype.Service;\n\nimport com.javacodegeeks.examples.dto.EventRequest;\nimport com.javacodegeeks.examples.dto.EventResponse;\nimport com.javacodegeeks.examples.entities.Artist;\n\n@Service\npublic class EventServiceImpl implements EventService {\n\n\tprivate EntityManagerFactory entityManagerFactory;\n\n\tpublic EventServiceImpl(EntityManagerFactory entityManagerFactory) {\n\t\tthis.entityManagerFactory = entityManagerFactory;\n\t}\n\n\t@Override\n\tpublic EventResponse getEventInfo(EventRequest request) {\t\n\t\tString name = request.getArtistName();\n\n\t\tEntityManager entityManager = entityManagerFactory.createEntityManager();\n\n\t\tentityManager.getTransaction().begin();\n\t\tQuery query = entityManager.createQuery(\"select a from Artist a where a.name = :name\");\n\t\tquery.setParameter(\"name\", name);\n\t\tArtist artist = (Artist) query.getSingleResult();\n\t\tentityManager.getTransaction().commit();\n\t\t\n\t\tEventResponse response = new EventResponse();\t\n\t\tresponse.setArtist(artist);\n\t\treturn response;\n\t}\n}\n\n<\/pre>\n<p>The class is marked with the <code>@Service<\/code> annotation, which makes it eligible for component scanning. The <code>EntityManagerFactory <\/code>is introduced using constructor-based injection.<\/p>\n<p>The <code>getEventInfo <\/code>method performs the following:<\/p>\n<ul class=\"wp-block-list\">\n<li>Retrieves the artist\u2019s name from the request payload. This value will bound to the named parameter in the query to retrieve the artist.<\/li>\n<li>Creates an <code>EntityManager <\/code>from the <code>EntityManagerFactory<\/code>.<\/li>\n<li>Uses the <code>EntityManager <\/code>to start a transaction.<\/li>\n<li>Creates a <code>Query <\/code>object using JPQL (Java Persistence Query Language).<\/li>\n<li>Sets the <em>name<\/em> parameter in the query.<\/li>\n<li>Executes the query, which returns a single result. (Remember that the artist name is unique.) <\/li>\n<li>Uses the <code>EntityManager <\/code>to commit the transaction.<\/li>\n<li>Sets the Artist object in the response.<\/li>\n<li>Returns the response.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">2.10 Configure the Application <\/h3>\n<p>Create a package&nbsp;<code>com.javacodegeeks.examples.config<\/code>&nbsp;and an class <code>EventConfig <\/code>with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>EventConfig.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.examples.config;\n\nimport javax.persistence.EntityManagerFactory;\nimport javax.xml.ws.Endpoint;\n\nimport org.apache.cxf.Bus;\nimport org.apache.cxf.jaxws.EndpointImpl;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\nimport com.javacodegeeks.examples.service.EventServiceImpl;\n\n@Configuration\npublic class EventConfig {\n\n\t@Autowired\n\tprivate Bus bus;\n\t\n\t@Autowired\n\tprivate EntityManagerFactory entityManagerFactory;\n\t\n\t@Bean\n\tpublic Endpoint endpoint() {\n\t\tEndpoint endpoint = new EndpointImpl(bus, new EventServiceImpl(entityManagerFactory));\n\t\tendpoint.publish(\"\/eventservice\");\n\t\treturn endpoint;\n\t}\n}\n\n<\/pre>\n<p>The <code>@Configuration<\/code> annotation indicates that this as a Spring configuration class. This permits us to declare <code>@Bean<\/code> methods. The <code>org.apache.cxf.Bus<\/code> and <code>EntityManagerFactory <\/code>are injected using the <code>@Autowired<\/code> annotation. <\/p>\n<p>The class defines a method <code>endpoint()<\/code> that returns a <code>javax.xml.ws.Endpoint<\/code>. <code>endpoint()<\/code> is annotated with&nbsp;<code>@Bean<\/code>&nbsp;so that the endpoint will be instantiated, configured and returned by the Spring container.. The method creates an <code>Endpoint <\/code>using the <code>EndpointImpl<\/code> constructor provided by the CXF JAX-WS library and passes in the Bus and our service implementation as parameters. (Note that we are passing the <code>EntityManagerFactory <\/code>to the <code>EventServiceImpl <\/code>constructor). Finally, we publish the endpoint at <em>&#8220;\/eventservice&#8221;<\/em> and return the <code>Endpoint<\/code>.<\/p>\n<h3 class=\"wp-block-heading\">2.11 Start the Web Service<\/h3>\n<p>Right-click the project in Project Explorer and select&nbsp;<em>Run As &gt; Spring Boot App.<\/em> Once the Spring Boot application has started, open a browser and enter the following URL:  <a rel=\"noreferrer noopener\" aria-label=\"http:\/\/localhost:8080\/services (opens in a new tab)\" href=\"http:\/\/localhost:8080\/services\" target=\"_blank\">http:\/\/localhost:8080\/services<\/a>.  You will see a link to the WSDL file on the \u201cAvailable SOAP services\u201d page. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"707\" height=\"398\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cxf-services-wm.jpg\" alt=\"\" class=\"wp-image-74636\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cxf-services-wm.jpg 707w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/cxf-services-wm-300x169.jpg 300w\" sizes=\"(max-width: 707px) 100vw, 707px\" \/><figcaption> Available SOAP Services<\/figcaption><\/figure>\n<\/div>\n<p>Click on the link to view the Event Service WSDL.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"685\" height=\"514\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/es-wsdl-wm.jpg\" alt=\"\" class=\"wp-image-74637\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/es-wsdl-wm.jpg 685w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/es-wsdl-wm-300x225.jpg 300w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><figcaption> Event Service WSDL<\/figcaption><\/figure>\n<\/div>\n<p>Copy the WSDL file&#8217;s URL. We will use it to configure the SOAP project in SoapUI.<\/p>\n<h3 class=\"wp-block-heading\">2.12 Test the Web Service with SoapUI<\/h3>\n<p>We\u2019ll test our web service with SoapUI. Start SoapUI and dismiss the popup window \u201c<em>Endpoint Explorer<\/em>\u201d. Create a new SOAP project by selecting&nbsp;<em>File &gt; New SOAP Project<\/em>. <\/p>\n<p>Enter a name for your project and paste the WSDL file&#8217;s URL in the&nbsp;<em>Initial WSDL<\/em>&nbsp;text box, for example, <em>http:\/\/localhost:8080\/services\/eventservice?wsdl<\/em>. Make sure <em>Create Requests<\/em> is selected and click \u201cOK\u201d.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"575\" height=\"272\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/new-soap-project-wm.jpg\" alt=\"\" class=\"wp-image-74602\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/new-soap-project-wm.jpg 575w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/new-soap-project-wm-300x142.jpg 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><figcaption>New SOAP Project<\/figcaption><\/figure>\n<\/div>\n<p>Expand <em>EventServiceImplServiceSoapBinding<\/em> and <em>getEventInfo <\/em>in the Navigator and double-click <em>Request 1<\/em>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"509\" height=\"402\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/service-request-wm.jpg\" alt=\"\" class=\"wp-image-74640\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/service-request-wm.jpg 509w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/service-request-wm-300x237.jpg 300w\" sizes=\"(max-width: 509px) 100vw, 509px\" \/><figcaption>SOAP Request<\/figcaption><\/figure>\n<\/div>\n<p>Enter \u201cThe Who\u201d for \u201cartistName\u201d and click the green submit arrow on the upper-left corner of the Request 1 window. You will see a list of events for &#8220;The Who&#8221; in the response.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"752\" height=\"410\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-who-wm-1.jpg\" alt=\"\" class=\"wp-image-74641\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-who-wm-1.jpg 752w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-who-wm-1-300x164.jpg 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><figcaption>SOAP Response<\/figcaption><\/figure>\n<\/div>\n<p>Now enter \u201cThe Rolling Stones\u201d for \u201cartistName\u201d and click the green submit arrow on the upper-left corner of the Request 1 window.  You will see a list of events for &#8221; The Rolling Stones&#8221; in the response.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"753\" height=\"410\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-rstones-wm.jpg\" alt=\"\" class=\"wp-image-74642\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-rstones-wm.jpg 753w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/the-rstones-wm-300x163.jpg 300w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><figcaption>SOAP Response<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">3. Summary<\/h2>\n<p>In this example, we demonstrated&nbsp;how to create a SOAP-based web service that uses Hibernate to read data from a database. <\/p>\n<h2 class=\"wp-block-heading\">4. Download the Source Code<\/h2>\n<p>This was a JAX-WS Hibernate example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:<br \/>\n<a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/jaxwshibernate.zip\"><strong>JAX-WS Hibernate Example<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we feature a comprehensive article on JAX-WS Hibernate. We will demonstrate&nbsp;how to create a SOAP-based web service that uses Hibernate to read data from a database. 1. Introduction Java API for XML Web Services (JAX-WS) is a technology for developing SOAP-based web services and clients. The API includes annotations for defining web &hellip;<\/p>\n","protected":false},"author":121,"featured_media":1240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[461],"tags":[840,1021,467,254],"class_list":["post-74343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jws","tag-apache-cxf","tag-hibernate","tag-soap","tag-web-services-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JAX-WS Hibernate Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JAX-WS Hibernate Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-11T08:00:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-11T09:39:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gilbert Lopez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gillopez_dev\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gilbert Lopez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\"},\"author\":{\"name\":\"Gilbert Lopez\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce\"},\"headline\":\"JAX-WS Hibernate Example\",\"datePublished\":\"2019-07-11T08:00:17+00:00\",\"dateModified\":\"2019-07-11T09:39:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\"},\"wordCount\":2327,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"keywords\":[\"apache cxf\",\"hibernate\",\"SOAP\",\"web services\"],\"articleSection\":[\"jws\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\",\"name\":\"JAX-WS Hibernate Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2019-07-11T08:00:17+00:00\",\"dateModified\":\"2019-07-11T09:39:18+00:00\",\"description\":\"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jws\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jws\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JAX-WS Hibernate Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce\",\"name\":\"Gilbert Lopez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg\",\"caption\":\"Gilbert Lopez\"},\"description\":\"Gilbert Lopez is an application developer and systems integration developer with experience building business solutions for large and medium-sized companies. He has worked on many Java EE projects. His roles have included lead developer, systems analyst, business analyst and consultant. Gilbert graduated from California State University in Los Angeles with a Bachelor of Science degree in Business.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\",\"https:\/\/www.linkedin.com\/in\/gilbertlopezdeveloper\",\"https:\/\/x.com\/gillopez_dev\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/gilbert-lopez\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JAX-WS Hibernate Example - Java Code Geeks","description":"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/","og_locale":"en_US","og_type":"article","og_title":"JAX-WS Hibernate Example - Java Code Geeks","og_description":"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-07-11T08:00:17+00:00","article_modified_time":"2019-07-11T09:39:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Gilbert Lopez","twitter_card":"summary_large_image","twitter_creator":"@gillopez_dev","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Gilbert Lopez","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/"},"author":{"name":"Gilbert Lopez","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce"},"headline":"JAX-WS Hibernate Example","datePublished":"2019-07-11T08:00:17+00:00","dateModified":"2019-07-11T09:39:18+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/"},"wordCount":2327,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","keywords":["apache cxf","hibernate","SOAP","web services"],"articleSection":["jws"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/","name":"JAX-WS Hibernate Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2019-07-11T08:00:17+00:00","dateModified":"2019-07-11T09:39:18+00:00","description":"Interested to learn more about JAX-WS? Then check out our detailed example on JAX-WS Hibernate where we demonstrate how to create a SOAP-based web service.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jws\/jax-ws-hibernate-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"jws","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jws\/"},{"@type":"ListItem","position":5,"name":"JAX-WS Hibernate Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce","name":"Gilbert Lopez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg","caption":"Gilbert Lopez"},"description":"Gilbert Lopez is an application developer and systems integration developer with experience building business solutions for large and medium-sized companies. He has worked on many Java EE projects. His roles have included lead developer, systems analyst, business analyst and consultant. Gilbert graduated from California State University in Los Angeles with a Bachelor of Science degree in Business.","sameAs":["https:\/\/www.javacodegeeks.com","https:\/\/www.linkedin.com\/in\/gilbertlopezdeveloper","https:\/\/x.com\/gillopez_dev"],"url":"https:\/\/examples.javacodegeeks.com\/author\/gilbert-lopez\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/121"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=74343"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1240"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=74343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=74343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=74343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}