Skip to main content
summaryrefslogtreecommitdiffstats
blob: f52a4b7178527f876826a2be4540cd2d35353f89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
##included template. Generates the @JoinTable, @JoinColumn or @JoinColumns annotation.
##Assumes that the context has a "role" object representing the generated AssociationRole
##
##macro joinColumn uses $column, $referencedColumn
#macro (joinColumn $column $referencedColumn)
#set ($members = "name=$customizer.quote($column.joinColumnName)")
#if( !$referencedColumn.primaryKey || $referencedColumn.partOfCompositePrimaryKey )
#set ($members = "$members, referencedColumnName=$customizer.quote($referencedColumn.name)")
#end
#if( $customizer.generateDDLAnnotations )
#if ($column.unique && !$column.primaryKey)
#set ($members = "$members, unique=true")
#end
#if (!$column.nullable)
#set ($members = "$members, nullable=false")
#end
#end
#if ($customizer.generateDDLAnnotations && !$role.association.joinTable && !$role.referrerTable.isColumnUpdateInsert($role, $column))
#set ($members = "$members, insertable=false, updatable=false")
#end
@JoinColumn($members)#end
##
##
##
#if ($role.association.joinTable)
#set ($joinTable = $role.association.joinTable)
	@JoinTable(
		name="${joinTable.joinTableAnnotationName}"
#if ($joinTable.schema!="")
		, schema="${joinTable.schema}"
#end
		, joinColumns={
#foreach ($column in $role.referrerColumns)
#set ($referencedColumn = $role.getReferencedColumn(${column.name}))
##$referencedColumn is the column in the join table
			#joinColumn($referencedColumn $column),
#end
			}
		, inverseJoinColumns={
#foreach ($column in $role.referencedColumns)
#set ($referencedColumn = $role.getReferrerColumn(${column.name}))
##$referencedColumn is the column in the join table
			#joinColumn($referencedColumn $column),
#end
			}
		)
#else
#if ($role.referrerColumns.size() == 1)
#set ($column = $role.referrerColumns.get(0))
#set ($referencedColumn = $role.getReferencedColumn(${column.name}))
#set ($referencedTableName = $role.getReferencedTable().getName() )
#set( $referencedTablePkName = $role.getReferencedTable().getPrimaryKeyColumn().name )
#set( $computedJoinColumnName = "${role.propertyName}_${referencedTablePkName}" )
#if($column.name.toUpperCase() != $computedJoinColumnName.toUpperCase() )
	#joinColumn($column $referencedColumn)

#elseif( $customizer.generateDDLAnnotations )
	#joinColumn($column $referencedColumn)

#end
#else
	@JoinColumns({
#foreach ($column in $role.referrerColumns)
#set ($referencedColumn = $role.getReferencedColumn(${column.name}))
		#joinColumn($column $referencedColumn),
#end		
		})
#end
#end

Back to the top