Announcement Announcement Module
Collapse
No announcement yet.
Hibernate one to one Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate one to one

    Hi guys

    another question. I can see that roo supports one to many relationships in hibernate.

    how about one to one?


    also is there a way to create the sql scripts from the entity objects?

    Thank you

  • #2
    Hi,

    To create a relationship you could use the 'add field reference jpa -type com.foo.Pet -fieldName myPet -class com.foo.Owner'. This will generate a field like this in Owner.java:

    Code:
        
    @ManyToOne
    @JoinColumn
    private Pet myPet;
    We are reviewing if it makes more sense to use JPA's @OneToOne relationship instead.

    also is there a way to create the sql scripts from the entity objects?
    I am not clear what exactly you are trying to do. But if you want to create your own query you could just use the JPA entityManager which is already existent in your JPA @Entity:

    Code:
        
    public List<Owner> test(){
       return entityManager.createQuery("select p from Owner p").getResultList();
    }
    Is this what you are referring to?

    -Stefan

    Comment


    • #3
      Hey Stefan

      thanks for the answer.

      The second part was more about if i can create "table statements" like create table Owner (id auto_increment int primary key, name varchar(50))

      from roo and its managed entities...

      Thanks

      btw where are you guys located? you have a very german name

      Comment


      • #4
        Hi,

        For the feature of executing SQL scripts upon application deployment you can take a look at the petclinic samples in Spring framework. They create tables and pre-populate the tables upon application start if that is what you are referring to. In the upcoming Spring 3 release we will also include a new feature which let's you configure that very conveniently for embedded databases via the application context.

        Ben and I are based in Sydney, Australia, but indeed I am German .


        -Stefan

        Comment


        • #5
          Nice thank you... i will take a look at those samples...

          Comment

          Working...
          X