Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thjanssen/e5e73369970c1c54b902 to your computer and use it in GitHub Desktop.
Save thjanssen/e5e73369970c1c54b902 to your computer and use it in GitHub Desktop.
JBoss Forge - Speedup your enterprise development (http://www.thoughts-on-java.org/2013/09/rapid-application-development-with.html)
@Entity
public class Author implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id = null;
@Version
@Column(name = "version")
private int version = 0;
@Column
private String lastName;
@Column
private String firstName;
@OneToMany(mappedBy = "author", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Book> books = new HashSet<Book>();
public Long getId()
{
return this.id;
}
public void setId(final Long id)
{
this.id = id;
}
public int getVersion()
{
return this.version;
}
public void setVersion(final int version)
{
this.version = version;
}
@Override
public boolean equals(Object that)
{
if (this == that)
{
return true;
}
if (that == null)
{
return false;
}
if (getClass() != that.getClass())
{
return false;
}
if (id != null)
{
return id.equals(((Author) that).id);
}
return super.equals(that);
}
@Override
public int hashCode()
{
if (id != null)
{
return id.hashCode();
}
return super.hashCode();
}
public String getLastName()
{
return this.lastName;
}
public void setLastName(final String lastName)
{
this.lastName = lastName;
}
public String getFirstName()
{
return this.firstName;
}
public void setFirstName(final String firstName)
{
this.firstName = firstName;
}
@Override
public String toString()
{
String result = getClass().getSimpleName() + " ";
if (lastName != null && !lastName.trim().isEmpty())
result += "lastName: " + lastName;
if (firstName != null && !firstName.trim().isEmpty())
result += ", firstName: " + firstName;
return result;
}
public Set<Book> getBooks()
{
return this.books;
}
public void setBooks(final Set<Book> books)
{
this.books = books;
}
}
entity --named Author
field string --named lastName
field string --named firstName
entity --named Book
field string --named title
field temporal --type DATE --named publicationDate
field int --named pages
new-project --named ForgeExample --topLevelPackage blog.thoughts.on.java.forge
field oneToMany --named books --fieldType blog.thoughts.on.java.forge.model.Book.java --inverseFieldName author
persistence setup --provider HIBERNATE --container JBOSS_AS7
scaffold setup
scaffold from-entity blog.thoughts.on.java.forge.model.*
forge install-plugin jboss-as-7
as7 setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment