camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: JSON to POJO using Apache Camel and hibernate
Date Tue, 14 May 2013 17:28:07 GMT
Hi

For the foregin key stuff, you may want to ask on Hibernate forums how
to do that.

And what hibernate component do you use? And what version is that?
As well what version of Hibernate.



On Tue, May 14, 2013 at 8:59 AM, bartleemans <bartleemans3@msn.com> wrote:
> Apache camel is using a route wich is listening to a specific url. the json
> from this url is then transformed to pojo classes and inserted in a mySQL
> database. Everything is working fine, except my foreign key still remains
> null. I'm using spring framework btw.
>
> Here is the url where you can find the data:
> https://builds.apache.org:443/job/Accumulo-1.5/api/json
>
> Here is my routedefinition for camel
>
> @Component
> public class JenkinsConfigurationRouteBuilder extends SpringRouteBuilder {
>
> private Logger logger =
> LoggerFactory.getLogger(JenkinsConfigurationRouteBuilder.class);
>
> @Override
> public void configure() throws Exception {
>
>     logger.info("Configuring route");
>
>     //Properties die hij niet vindt in de klasse negeren
>     ObjectMapper objectMapper = new ObjectMapper();
>
> objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
> false);
>
>     DataFormat jenkinsConfigFormat = new JacksonDataFormat(objectMapper,
> JenkinsConfiguration.class);
>
>     from("timer://foo?fixedRate=true&delay=0&period=200000&repeatCount=1")
>             .routeId("jsonToJenkinsConfiguration")
>             .setHeader(Exchange.HTTP_METHOD, constant("GET"))
>             .to("https://builds.apache.org:443/job/Accumulo-1.5/api/json")
>             .convertBodyTo(String.class)
>             .unmarshal(jenkinsConfigFormat) //instance van
> JenkinsConfiguration
>             .log(LoggingLevel.DEBUG, "be.kdg.teamf", "Project: ${body}")
>             .to("hibernate:be.kdg.teamf.model.JenkinsConfiguration");
>
>
>     }
>
> My POJO class
>
> @Entity(name = "jenkinsConfiguration")
> public class JenkinsConfiguration extends Configuration implements
> Serializable {
>
> @Column
> @JsonProperty("displayName")
> private String name;
>
> @JsonProperty("healthReport")
> @JsonIgnore
> @LazyCollection(LazyCollectionOption.FALSE)
> @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy =
> ("jenkinsConfig"))
> private Collection<HealthReport> healthReport;
>
> @JsonProperty("builds")
> @JsonIgnore
> @LazyCollection(LazyCollectionOption.FALSE)
> @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy =
> ("jenkinsConfig"))
> private Collection<Build> builds;
>
> @JsonProperty("modules")
> @JsonIgnore
> @LazyCollection(LazyCollectionOption.FALSE)
> @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy =
> ("jenkinsConfig"))
> private Collection<Module> modules;
>
>
> public JenkinsConfiguration() {
> }
>
> public JenkinsConfiguration(Collection<Build> builds,
> Collection<HealthReport> healthReport, Collection<Module> modules, String
> name) {
>     this.builds = builds;
>     this.healthReport = healthReport;
>     this.modules = modules;
>     this.name = name;
> }
>
> public Collection<Build> getBuilds() {
>     return builds;
> }
>
> public Collection<HealthReport> getHealthReport() {
>     return healthReport;
> }
>
> public Collection<Module> getModules() {
>     return modules;
> }
>
> public String getName() {
>     return name;
> }
>
> public void setBuilds(Collection<Build> builds) {
>     this.builds = builds;
> }
>
> public void setHealthReport(Collection<HealthReport> healthReport) {
>     this.healthReport = healthReport;
> }
>
> public void setModules(Collection<Module> modules) {
>     this.modules = modules;
> }
>
> public void setName(String name) {
>     this.name = name;
> }
>
> @Override
> public String toString() {
>     return ToStringBuilder.reflectionToString(this);
> }
>
> }
> }
>
> Let us take the builds for instance. As you can see, this pojo class
> contains a list from builds. A JenkinsConfiguration can contain more builds.
> One build belongs to one JenkinsConfiguration.
>
> This is my Build class:
>
> @XmlRootElement(name = "builds")
> @Entity(name = "build")
> public class Build implements Serializable {
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> private int Id;
>
> @Column
> @JsonProperty("number")
> private Integer number;
>
> @Column
> @JsonProperty("url")
> private String url;
>
> @JsonBackReference
> @OnDelete(action = OnDeleteAction.CASCADE)
> @ManyToOne(fetch = FetchType.LAZY)
> @JoinColumn(name = "jenkinsConfig")
> private JenkinsConfiguration jenkinsConfig;
>
> public Build() {
>
> }
>
> public Build(JenkinsConfiguration jenkinsConfig, Integer number, String url)
> {
>     this.jenkinsConfig = jenkinsConfig;
>     this.number = number;
>     this.url = url;
> }
>
> public int getId() {
>     return Id;
> }
>
> public JenkinsConfiguration getJenkinsConfig() {
>     return jenkinsConfig;
> }
>
> public Integer getNumber() {
>     return number;
> }
>
> public String getUrl() {
>     return url;
> }
>
> public void setId(int id) {
>     Id = id;
> }
>
> public void setJenkinsConfig(JenkinsConfiguration jenkinsConfig) {
>     this.jenkinsConfig = jenkinsConfig;
> }
>
> public void setNumber(Integer number) {
>     this.number = number;
> }
>
> public void setUrl(String url) {
>     this.url = url;
> }
> }
>
> My question: how come that my foreign key is not set for the build class? it
> remains null. Doe I need to update it manually or something? If so, can I do
> this using camel by getting all the rows from my database and then updating
> them?
>
> Any help would me much appreciated!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/JSON-to-POJO-using-Apache-Camel-and-hibernate-tp5732466.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message