Search code examples
javajpatelosys

How to generate @OneToOne and @ManyToMany JPA relations in Telosys using Dsl Model


Im trying to generate classes using my own springboot template and Dsl models. In my ".entity" files I have:

Car {​​​​​
id : int {​​​​​ @Id, @AutoIncremented }​​​​​;
users : Employee [];
}​​​​​
    
Employee {​​​​​
id : long {​​​​​ @Id }​​​​​ ;
name : string ;
cars : Car[] ;
}​​​​​

I was expecting a @ManyToMany relation in JPA but I didn't. The same thing with this:

Car {​​​​​
id : int {​​​​​ @Id, @AutoIncremented }​​​​​;
user : Employee;
}​​​​​
    
Employee {​​​​​
id : long {​​​​​ @Id }​​​​​ ;
name : string ;
car : Car;
}​​​​​

I expect a @OneToOne relation but I don't get it. It seems I can only get @ManyToOne and @OneToMany. How can I get @ManyToMany and @OneToOne relations using DSL models?


Solution

  • Since Telosys 3.3.0 you can do that with “@OneToOne” and “@ManyToMany” DSL model annotations.

    Add annotation for the relevant link, for example :

    MyEntity {
      ...
      employee : Employee  { @OneToOne   @FetchTypeLazy  } ; 
      projects : Project[] { @ManyToMany @LinkByJoinEntity(EmpProj) } ;
    }
    

    See the doc :