Skip to content

Instantly share code, notes, and snippets.

@dunst0
Created Aug 21, 2011
Embed
What would you like to do?
java plugin
import java.util.List;
import javax.persistence.PersistenceException;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin {
@Override
public void onLoad() {
//some more code
setupDatabase();
}
@Override
public List<Class<?>> getDatabaseClasses() {
List<Class<?>> classes = super.getDatabaseClasses();
classes.add(ToBeSaved.class);
return classes;
}
private void setupDatabase() {
try {
getDatabase().find(ToBeSaved.class).findRowCount();
} catch (PersistenceException e) {
installDDL();
}
}
}
import com.avaje.ebean.validation.NotNull;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class ToBeSaved implements Serializable {
private static final long serialVersionUID = 3611041942327901641L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
private String name;
public Relation() {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment