Results 1 to 5 of 5

Thread: Hibernate one to one

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    8

    Default 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. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    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

  3. #3
    Join Date
    Jun 2009
    Posts
    8

    Default

    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

  4. #4
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    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

  5. #5
    Join Date
    Jun 2009
    Posts
    8

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •