{"action":"created","issue":{"url":"https://api.github.com/repos/sculptor/sculptor/issues/175","labels_url":"https://api.github.com/repos/sculptor/sculptor/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/sculptor/sculptor/issues/175/comments","events_url":"https://api.github.com/repos/sculptor/sculptor/issues/175/events","html_url":"https://github.com/sculptor/sculptor/issues/175","id":71213113,"number":175,"title":"Templates: The oneToOneJpaAnnotation should be orphanRemoval if the referenced-to object is not an aggregateRoot","user":{"login":"zhongweijun","id":6158512,"avatar_url":"https://avatars.githubusercontent.com/u/6158512?v=3","gravatar_id":"","url":"https://api.github.com/users/zhongweijun","html_url":"https://github.com/zhongweijun","followers_url":"https://api.github.com/users/zhongweijun/followers","following_url":"https://api.github.com/users/zhongweijun/following{/other_user}","gists_url":"https://api.github.com/users/zhongweijun/gists{/gist_id}","starred_url":"https://api.github.com/users/zhongweijun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhongweijun/subscriptions","organizations_url":"https://api.github.com/users/zhongweijun/orgs","repos_url":"https://api.github.com/users/zhongweijun/repos","events_url":"https://api.github.com/users/zhongweijun/events{/privacy}","received_events_url":"https://api.github.com/users/zhongweijun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-04-27T08:18:53Z","updated_at":"2015-05-18T10:45:28Z","closed_at":null,"body":"First of all, if I am not wrong, the property settings of \"cascade.aggregate\" and \"cascade.aggregate.oneToMany\" in the sculptor-generator.properties file doesn't take effect at all in the lastest versions of SculptorGenerator.\r\n\r\nAnd then, in the DomainObjectReferenceAnnotationTmpl file, the orphanRemoval strategies for OneToOne relationships and OneToMany relationships are quite different for referenced objects which are not aggregateRoot. For OneToMany relationships, the orphanRemoval is marked true for non-aggregateRoot, But for OneToOne relationships, the orphanRemoval is marked as false by default.\r\n\r\nI think it's better to keep their default behavior same (that is, orphanRemovel=true for non-aggregateRoot objects). \r\n\r\nBelow is the original code from DomainObjectReferenceAnnotationTmpl class:\r\n~~~\r\ndef String oneToOneJpaAnnotation(Reference it) {\r\n\t'''\r\n\t\t@javax.persistence.OneToOne(\r\n\t\t\t«formatAnnotationParameters(<Object>newArrayList(!nullable, \"optional\", false,\r\n\t\t\t\tisInverse(), \"mappedBy\", '\"' + opposite.name + '\"',\r\n\t\t\t\tit.getCascadeType() != null, \"cascade\", it.getCascadeType(),\r\n\t\t\t\tisOrphanRemoval(it.getCascadeType()), \"orphanRemoval\", true,\r\n\t\t\t\tit.getFetchType() != null, \"fetch\", it.getFetchType()\r\n\t\t\t))»)\r\n\t\t«IF !isInverse()»\r\n\t\t\t@javax.persistence.JoinColumn(\r\n\t\t\t«formatAnnotationParameters(<Object>newArrayList(true, \"name\", '\"' + it.getDatabaseName() + '\"',\r\n\t\t\t\t!isJpaProviderOpenJpa() && !nullable, \"nullable\", false,\r\n\t\t\t\tit.isSimpleNaturalKey(), \"unique\", \"true\"\r\n\t\t\t))»)\r\n\t\t\t«IF isJpaProviderHibernate()»\r\n\t\t\t\t@org.hibernate.annotations.ForeignKey(name = \"FK_«truncateLongDatabaseName(from.getDatabaseName(), it.getDatabaseName())»\")\r\n\t\t\t\t«IF it.getHibernateFetchType() != null»\r\n\t\t\t\t\t@org.hibernate.annotations.Fetch(«it.getHibernateFetchType()»)\r\n\t\t\t\t«ENDIF»\r\n\t\t\t«ENDIF»\r\n\t\t«ENDIF»\r\n\t'''\r\n}\r\n\r\ndef String oneToManyJpaAnnotation(Reference it) {\r\n\t'''\r\n\t\t@javax.persistence.OneToMany(\r\n\t\t\t«formatAnnotationParameters(<Object>newArrayList(it.getCascadeType() != null, \"cascade\", it.getCascadeType(),\r\n\t\t\t\tisOrphanRemoval(it.getCascadeType(), it), \"orphanRemoval\", true,\r\n\t\t\t\tit.hasOpposite() && (getCollectionType() != \"list\"), \"mappedBy\", '\"' + opposite?.name + '\"',\r\n\t\t\t\tit.getFetchType() != null, \"fetch\", it.getFetchType()\r\n\t\t\t))»)\r\n\t\t«IF isJpaProviderHibernate() && !isInverse()»\r\n\t\t\t@org.hibernate.annotations.ForeignKey(\r\n\t\t\t\tname = \"FK_«truncateLongDatabaseName(it.getManyToManyJoinTableName(), it.getOppositeForeignKeyName())»\"\r\n\t\t\t\t, inverseName = \"FK_«truncateLongDatabaseName(it.getManyToManyJoinTableName(), it.getForeignKeyName())»\")\r\n\t\t«ENDIF»\r\n\t\t«/* TODO: add support for unidirectional onetomany relationships with and without jointable */»\r\n\t\t«/*\r\n\t\t«IF !it.isUnidirectionalToManyWithoutJoinTable() && isJpa2()»\r\n\t\t\t@javax.persistence.JoinTable(\r\n\t\t\t\tname = \"«it.getManyToManyJoinTableName()»\",\r\n\t\t\t\tjoinColumns = @javax.persistence.JoinColumn(name = \"«it.getOppositeForeignKeyName()»\"),\r\n\t\t\t\tinverseJoinColumns = @javax.persistence.JoinColumn(name = \"«it.getForeignKeyName()»\"))\r\n\t\t«ENDIF»\r\n\t\t */»\r\n\t\t«IF isInverse() && (!it.hasOpposite() || it.isList())»\r\n\t\t\t@javax.persistence.JoinColumn(name = \"«it.getOppositeForeignKeyName()»\")\r\n\t\t\t\t«IF isJpaProviderHibernate()»\r\n\t\t\t\t\t@org.hibernate.annotations.ForeignKey(name = \"FK_«truncateLongDatabaseName(from.getDatabaseName(), to.getDatabaseName())»\")\r\n\t\t\t\t«ENDIF »\r\n\t\t«ENDIF»\r\n\t'''\r\n}\r\n~~~\r\n"},"comment":{"url":"https://api.github.com/repos/sculptor/sculptor/issues/comments/103013751","html_url":"https://github.com/sculptor/sculptor/issues/175#issuecomment-103013751","issue_url":"https://api.github.com/repos/sculptor/sculptor/issues/175","id":103013751,"user":{"login":"zhongweijun","id":6158512,"avatar_url":"https://avatars.githubusercontent.com/u/6158512?v=3","gravatar_id":"","url":"https://api.github.com/users/zhongweijun","html_url":"https://github.com/zhongweijun","followers_url":"https://api.github.com/users/zhongweijun/followers","following_url":"https://api.github.com/users/zhongweijun/following{/other_user}","gists_url":"https://api.github.com/users/zhongweijun/gists{/gist_id}","starred_url":"https://api.github.com/users/zhongweijun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhongweijun/subscriptions","organizations_url":"https://api.github.com/users/zhongweijun/orgs","repos_url":"https://api.github.com/users/zhongweijun/repos","events_url":"https://api.github.com/users/zhongweijun/events{/privacy}","received_events_url":"https://api.github.com/users/zhongweijun/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T10:45:28Z","updated_at":"2015-05-18T10:45:28Z","body":"Adopt the User model makes no sense. The model:\r\n \r\n Entity User {\r\n            String userName key;\r\n            - @EmailAddress officialEmailAddress;\r\n            - List<@EmailAddress> privateEmailAddresses;\r\n            - List<@Address> privateAddress;\r\n        } \r\n\r\nThe Result:\r\n\r\n\t@ManyToMany(cascade = CascadeType.ALL)\r\n\t@JoinTable(name = \"PRIVATEADDRESS_USER\", joinColumns = @JoinColumn(name = \"USER\"), inverseJoinColumns = @JoinColumn(name = \"PRIVATEADDRESS\"))\r\n\t@ForeignKey(name = \"FK_PRIVATEADDRESS_USER_USER\", inverseName = \"FK_PRIVATEADDRESS_USER_PRIVATEADDRESS\")\r\n\t@NotNull\r\n\tprivate Set<Address> privateAddress = new HashSet<Address>();\r\n"}}