Available as of Camel 2.11
This example is located in the examples/camel-example-hibernate directory of the Camel Extras project.
The source code for this example can be viewed online at this link
If you use maven then you can easily compile and install the example from the command line:
This example shows how to exchange data using a shared database table.
The example has two Camel routes. The first route insert new data into the table, triggered by a timer to run every 5th second.
In the camel-context.xml file in the src/main/resources/META-INF/spring folder we have the Spring XML file to setup and configure the database and Hibernate, as well the CamelContext.
And in the same file we setup Hibernate. At first we have the Camel Hibernate component, and then a number of beans to setup transactions. And then the last bean setup the Hibernate session factory where we refer to the data source and the hibernate mapping files, and any other hibernate configurations we may need.
And then in the same file we setup our Camel application. At first we have a orderBean that we use in the routes to generate new orders and process orders as well.
In this example we have a Order POJO in the class org.apacheextras.camel.examples.hibernate.Order which we use Hibernate to map to/from the database. The Order pojo is just a bean with the following attributes with getter/setter
The Order pojo is mapped to Hibernate using the mapping file Order.hbm.xml which is located in the src/main/resources directory of the example
This example can be run from the command line
Press ctrl + c to stop the example.
When running this example you should see logging in the console about orders being processed, for example as shown below: