Reputation: 23
Im trying to generate JPA enitites using a dsl model in Telosys.
My Dsl model:
Car {
id : int { @Id, @AutoIncremented };
user : Employee;
}
Employee {
id : long { @Id } ;
name : string ;
cars : Car[] ;
}
Im using this code:
$jpa.linkAnnotations(4, $link, $entity.nonKeyAttributes)
private ${link.fieldType} $link.fieldName ;
#end
And I always have a result like this:
@OneToMany(mappedBy="null", targetEntity=Car.class)
private List<Car> cars ;
@ManyToOne
private Employee user ;
My problem is, I always get mappedBy="null", how can I fix this?
Upvotes: 1
Views: 309
Reputation: 2460
This is a bug that occurs in the case of an "Inverse Side" type link in a "DSL model". This problem is caused by the absence of Foreign Key definition in the DSL models. The Foreign Keys have been added in the new DSL model grammar and will be usable in the next version of Telosys (comming soon).
The "$jpa" object provides a set of functions that serve as writing shortcuts, so in the meantime you can also create a Velocity macro to replace the "linkAnnotations" function by your own code (in pure Velocity language).
For example a macro named "jpaLinkAnnot" :
#macro( jpaLinkAnnot $link)
#if ( $link.isOwningSide() )
// Owning Side
$jpa.linkAnnotations(4, $link, $entity.nonKeyAttributes)
#else
// Inverse Side
#if ( $link.isCardinalityOneToMany() )
@OneToMany(targetEntity=${link.targetEntity.name}.class )
#else
$jpa.linkAnnotations(4, $link, $entity.nonKeyAttributes)
#end
#end
#end
#foreach( $link in $entity.selectedLinks )
## Macro below replaces '$jpa.linkAnnotations(...)'
#jpaLinkAnnot($link)
private ${link.formattedFieldType(10)} $link.formattedFieldName(12) ;
#end
Upvotes: 2