Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To use the feature, you need to add the following dependency to your pom.xml:

Code Block

<dependency>
  <groupId>org.tynamo</groupId>
  <artifactId>tapestry-hibernate-seedentity</artifactId>
  <version>0.1.0</version>
</dependency>

Simply contribute your entities in the right order (starting from the leaf node) and you are done! Take a look at the following example:

Code Block
	@Contribute(SeedEntity.class)
	public static void contributeSeedEntityaddSeedEntities(OrderedConfiguration<Object> configuration) {
		User admin = new User();
		admin.setUsername("admin");
		admin.setPassword("admin");
		Set<User.Role> adminRoles = new HashSet<User.Role>();
		adminRoles.add(User.Role.admin);
		admin.setRoles(adminRoles);
		configuration.add("admin", admin);

		if (productionMode) return;

		// TEST entities
		Game game = new Game();
		game.setName("Texas Hold'em of the Month");
		Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
		game.setStartDate(calendar.getTime());
		game.add(GregorianCalendar.DAY_OF_YEAR, 31);
		game.setEndDate(calendar.getTime());
		configuration.add("game1", game);

		User user = new User();
		user.setUsername("user");
		user.setPassword("user");
		Set<Game> gamesParticipated = new HashSet<Game>();
		gamesParticipated.add(game);
		user.setGames(gamesParticipated);
		configuration.add("testuser1", user);
	}

The module uses standard Hibernate annotations

Code Block

@NaturalId, 
@Column(unique = true) or 
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = {...}) }) 

...