Trying to understand persistence

Discussion in 'Plugin Development' started by Sammy, Apr 9, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Sammy

    Hey,
    My knowledge about persistence and databases is next to zero... ok it's zero ^^
    Still, I'm trying to understand how the Home plugin works.
    Home Class
    SetHome

    Code:
    Home home = plugin.getDatabase().find(Home.class).where().ieq("name", name).ieq("playerName", player.getName()).findUnique();
    In this part of the code he's searching for the player using the variables name and playername ?
    Are does variables different from the rest? or you can use any variable to find the tables row ?

    More questions are emerging:

    The class I'm persisting is asking me to either choose a "Persistence Unit name" or implementing "import java.io.Serializable;" can some one help me ?

    Errors :
    Code:
    22:27:57 [SEVERE] ebean.properties not found
    22:27:57 [INFO] DataSourcePool [sdRankingSystem] autoCommit[false] transIsolation[SERIALIZABLE] min[2] max[20]
    >>>22:27:57 [INFO] SubClassFactory parent ClassLoader [org.bukkit.plugin.java.PluginClassLoader]
    22:27:57 [SEVERE] Bean property com.SySammy.sdRankingSys.Ranks.id has  missing readMethod  missing writeMethod . Should it be transient?
    22:27:58 [INFO] Entities enhanced[0] subclassed[1]
     
  2. Offline

    Mixcoatl

    Code:
    Home home = plugin.getDatabase(). // We want to use database persistence.
        find(Home.class). // We're looking for an object of class "Home"
        where(). // "Where" begins our critera.
        ieq("name", name). // Compare Home.name with our name variable (case insensitively)
        ieq("playerName",player.getName()). // Compare Home.playerName with player.getName (case insensitively).
        findUnique(); // We want only the first object we find, not more than one object.
    Examine the Home class in the example. Specifically, you want to look at the annotations (the lines that begin with at at sign.)
    This means you didn't create an ebeans.properties file in your bukkit directory.
    This isn't important. I'm not even certain why the Bukkit people decided to log it.
    This is more important.
    This means you didn't declare a Java Bean getter method for one of the class' properties. For each property you need a method called get<Property>, the getter, and a method called set<Property>, the setter. For example:
    Code:
    @Entity()
    @Table(name="my_class")
    class MyClass {
        // Java beans compliant getter.
        public String getName() {
            return name;
        }
        // Java Beans compliant setter.
        public void setName(String name) {
            this.name = null;
            if (name != null && name.trim().length() != 0) {
                this.name = name.trim();
            }
        }
        @Column(unique=true)
        private String name;
    }
     
  3. Offline

    Sammy

    Thank you every much for the help, I'm trying to implement the changes, if everything works you are freee ^^
    Just kidding, thank you again :)
     
  4. Offline

    Mixcoatl

    It may seem like a pain, perhaps even complicated, but this is far, far easier than writing all of the code to support database persistence on your own.
     
    Sammy likes this.
  5. Offline

    Sammy

    Well I'm greener then I thought... :(

    Code:
    java.io.FileNotFoundException: Jar does not contain plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:57)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:158)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:106)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:84)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:215)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:202)
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:142)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:257)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)
    23:15:50 [INFO] [Permissions] version [2.6] (Phoenix)  loaded
    23:15:50 [INFO] Permissions is enable for sdBountyHunter.
    23:15:50 [INFO] SdBountyHunter version 2.2 is enabled!
    23:15:50 [INFO] Permissions is enable for sdBountyHunter.
    23:15:50 [INFO] SdCurrency version 2.3 is enabled!
    23:15:50 [INFO] Permissions is enable for sdBountyHunter.
    23:15:50 [INFO] sdMiningChallenge version 1.0 is enabled!
    23:15:50 [INFO] Permissions is enable for sdBountyHunter.
    23:15:50 [INFO] sdQuests version 1.0 is enabled!
    23:15:50 [INFO] Permissions is enable for sdBountyHunter.
    23:15:50 [INFO] sdRankingSystem version 0.1 is enabled!
    23:15:50 [INFO] sdRPGMod version 0.1 is enabled!
    23:15:50 [INFO] Done (0,165s)! For help, type "help" or "?"
    >>>>>>>>>>>>>>>>>>23:15:54 [INFO] Dergott [/127.0.0.1:60834] logged in with entity id 190
    23:15:54 [SEVERE] Nag author: 'Deck & Sammy' of 'SdCurrency' about the following: onPlayerJoin has been replaced with a new signature, (PlayerJoinEvent)
    >>23:16:16 [INFO] Can not test connection as heartbeatsql is not set
    23:16:16 [INFO] Closing Connection[sdRankingSystem.1] psReuse[0] psCreate[1] psSize[0]
    23:16:16 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'rank' in plugin sdRankingSystem v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:254)
            at net.minecraft.server.NetServerHandler.c(NetServerHandler.java:596)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:559)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:553)
            at net.minecraft.server.Packet3Chat.a(SourceFile:24)
            at net.minecraft.server.NetworkManager.a(NetworkManager.java:198)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:72)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:368)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:283)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)
    Caused by: javax.persistence.PersistenceException: Query threw SQLException:[SQLITE_ERROR] SQL error or missing database (no such table: hb_ranks)
    Bind values:[null]
    Query was:
    select t0.id c0, t0.name c1, t0.player_name c2
    from hb_ranks t0
    where lower(t0.name) =?  and lower(t0.player_name) =?
    
            at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:849)
            at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:829)
            at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:238)
            at com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:104)
            at com.avaje.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:344)
            at com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1469)
            at com.avaje.ebeaninternal.server.core.DefaultServer.findUnique(DefaultServer.java:1236)
            at com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery.findUnique(DefaultOrmQuery.java:924)
            at com.avaje.ebeaninternal.util.DefaultExpressionList.findUnique(DefaultExpressionList.java:217)
            at com.SySammy.sdRankingSys.sdRankCmds.RankMethod(sdRankCmds.java:36)
            at com.SySammy.sdRankingSys.sdRankCmds.onCommand(sdRankCmds.java:25)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
            ... 12 more
    Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: hb_ranks)
            at org.sqlite.DB.newSQLException(DB.java:383)
            at org.sqlite.DB.newSQLException(DB.java:387)
            at org.sqlite.DB.throwex(DB.java:374)
            at org.sqlite.NativeDB.prepare(Native Method)
            at org.sqlite.DB.prepare(DB.java:123)
            at org.sqlite.PrepStmt.<init>(PrepStmt.java:42)
            at org.sqlite.Conn.prepareStatement(Conn.java:404)
            at org.sqlite.Conn.prepareStatement(Conn.java:399)
            at org.sqlite.Conn.prepareStatement(Conn.java:383)
            at com.avaje.ebeaninternal.server.lib.sql.PooledConnection.prepareStatement(PooledConnection.java:426)
            at com.avaje.ebeaninternal.server.lib.sql.PooledConnection.prepareStatement(PooledConnection.java:396)
            at com.avaje.ebeaninternal.server.query.CQuery.prepareBindExecuteQuery(CQuery.java:399)
            at com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:198)
            ... 21 more
    >>>
    So I still need to add a database ?
    How do I do it ? sorry I never worked with persistence or databases... I always stay on the plain txt files level :p
     
  6. Offline

    Mixcoatl

    This means the plug-in's .jar file does not contain a plugin.yml file.
    This means you're using a deprecated (bad) version of the onPlayerJoin event. You need to change the signature of this event to match the new one. Comment out your existing method and then right-click and choose Source and Override methods, then pick onPlayerJoin.
    I'm guessing you haven't set the heartbeat SQL. I'm not certain to what this should be set. I left mine with the default value I think.
    Looks like you didn't install the database schema. Go look at the onEnable method in the HomeBukkit plug-in to see how this is done.
    I'm not sure what you're asking me, here. Bukkit should create the database and any necessary schema for you if you follow the HomeBukkit example.
     
    Sammy likes this.
  7. Offline

    Sammy

    Silly me, I forgot to add the method to OnEnable :oops:
    Now I have an error then I try to save the data base err, but I'm going to try and fix it without bordering you :)
    Thanks again!!!

    @Mixcoatl
    Sorry man I really can't find my error =/

    The error occurs on "plugin.getDatabase().save(rankClass);"
    Code:
    >>00:26:13 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'rank' in plugin sdRankingSystem v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:254)
            at net.minecraft.server.NetServerHandler.c(NetServerHandler.java:596)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:559)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:553)
            at net.minecraft.server.Packet3Chat.a(SourceFile:24)
            at net.minecraft.server.NetworkManager.a(NetworkManager.java:198)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:72)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:368)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:283)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)
    Caused by: java.lang.RuntimeException: get Tretas on [com.SySammy.sdRankingSys.Ranks] type[com.SySammy.sdRankingSys.Ranks] threw error.
            at com.avaje.ebeaninternal.server.deploy.BeanProperty.getValue(BeanProperty.java:872)
            at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.validate(BeanDescriptor.java:1372)
            at com.avaje.ebeaninternal.server.core.PersistRequestBean.validate(PersistRequestBean.java:505)
            at com.avaje.ebeaninternal.server.persist.DefaultPersistExecute.executeInsertBean(DefaultPersistExecute.java:89)
            at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:527)
            at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:557)
            at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:404)
            at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveVanillaInsert(DefaultPersister.java:377)
            at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveVanillaRecurse(DefaultPersister.java:361)
            at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveRecurse(DefaultPersister.java:308)
            at com.avaje.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:282)
            at com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1577)
            at com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1567)
            at com.SySammy.sdRankingSys.sdRankCmds.RankMethod(sdRankCmds.java:45)
            at com.SySammy.sdRankingSys.sdRankCmds.onCommand(sdRankCmds.java:25)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
            ... 12 more
    Caused by: java.lang.NullPointerException
            at com.avaje.ebeaninternal.server.deploy.BeanProperty.getValue(BeanProperty.java:867)
            ... 27 more
    >
    Here is my ebean.properties file

    Code:
    # -------------------------------------------------------------
    # Load (Dev/Test/Prod) properties external to your war/jar
    # -------------------------------------------------------------
    # You can use load.properties to load the properties from a
    # file external to your war/jar.
    #load.properties.override=${CATALINA_HOME}/conf/myapp.ebean.properties
     
    ebean.ddl.generate=false
    ebean.ddl.run=false
    
    ebean.debug.sql=true
    ebean.debug.lazyload=false
     
    # -------------------------------------------------------------
    # Transaction Logging
    # -------------------------------------------------------------
    
    # Use java util logging to log transaction details
    #ebean.loggingToJavaLogger=true
    
    # General logging level: (none, explicit, all)
    ebean.logging=all
    
    # Sharing log files: (none, explicit, all)
    ebean.logging.logfilesharing=all
    
    # location of transaction logs
    ebean.logging.directory=logs
    #ebean.logging.directory=${catalina.base}/logs/trans
    
    # Specific Log levels (none, summary, binding, sql)
    ebean.logging.iud=sql
    ebean.logging.query=sql
    ebean.logging.sqlquery=sql
    
    ebean.logging.txnCommit=none
    
    # -------------------------------------------------------------
    # DataSources (If using default Ebean DataSourceFactory)
    # -------------------------------------------------------------
    # You can specify many DataSources (one per EbeanServer)  and
    # one of them is defined as the default/primary DataSource
    
    # specify the default/primary DataSource
    datasource.default=ora
    
    datasource.ora.username=bukkit
    datasource.ora.password=walrus
    datasource.ora.databaseUrl=jdbc:sqlite:{DIR}{NAME}.db
    datasource.ora.databaseDriver=org.sqlite.JDBC
    datasource.ora.minConnections=1
    datasource.ora.maxConnections=25
    datasource.ora.heartbeatsql=select count(*) from dual
    datasource.ora.isolationlevel=read_committed
    I grab it from the ebean website and changed the username password databaseUrl and dataBaseDriver to match the info on the Bukkit.yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  8. Offline

    Mixcoatl

    There error seems to occur here:
    This is the error:
    I'm not certain that "Tretas" is, but it looks like its getter raised an exception. That would be my first guess, anyhow. It's hard to guess without code to look at (and sometimes it's hard to guess even with code to look at.)
     
  9. Offline

    Sammy

    You right I'm sorry, "tretas" is the name of the variable I wanna store as a test:

    Code:
    @Entity()
    @Table(name = "sd_ranks")
    public class Ranks {
    
        @Id
        private int id;
        @NotNull
        private String playerName;
        @Length(max = 30)
        @NotEmpty
        private String name;
        @NotEmpty
        private String tretas;
    
        public void setId(int id) {
            this.id = id;
        }
    
        public int getId() {
            return id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getPlayerName() {
            return playerName;
        }
    
        public void setPlayerName(String ply) {
            this.playerName = ply;
        }
    
        public Player getPlayer() {
            return Bukkit.getServer().getPlayer(playerName);
        }
    
        public void setPlayer(Player player) {
            this.playerName = player.getName();
        }
    
        public void setTreta(String treta) {
            this.tretas = treta;
        }
    
        public String getTreta() {
            return tretas;
        }
    }
    If i take her off everything works...
    I declare it like this:

    Code:
                Ranks rankClass = plugin.getDatabase().find(Ranks.class).where().ieq("name", name).ieq("playerName", ply.getName()).findUnique();
                if (rankClass == null) {
                    rankClass = new Ranks();
                    rankClass.setPlayer(ply);
                    rankClass.setName(name);
                }
                rankClass.setTreta("test");
                plugin.getDatabase().save(rankClass);
     
  10. Offline

    Mixcoatl

    Your variable is called tretas, but your getter is called getTreta, and your setter setTreta. The getter and setter names must match the name of the property.
     
    Sammy likes this.
  11. Offline

    Sammy

    Finally :D thank you very much !!
    If you don't mind, I going to make a in depth tutorial in how to use this... giving you all the needed credit
    Tks again
    cheers
     
  12. Offline

    Mixcoatl

    Happy to help!
    I don't really need any special credit. Just glad you got it working! I appreciate the gesture, though!
     
  13. Offline

    vildaberper

    I really want to learn this stuff, but its next to impossible. "/
    No tutorials or anything...

    Heres my error:
    Show Spoiler

    03:28:11 [INFO] DataSourcePool [Locker] autoCommit[false] transIsolation[SERIAL
    ZABLE] min[2] max[20]
    03:28:11 [INFO] SubClassFactory parent ClassLoader [org.bukkit.plugin.java.Plug
    nClassLoader]
    03:28:11 [ALLVARLIG] Error in deployment
    java.lang.RuntimeException: java.lang.NoSuchMethodException: com.vildaberper.Lo
    ker.Lock.<init>()
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.defaultCon
    tructor(EnhanceBeanReflect.java:69)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.<init>(Enh
    nceBeanReflect.java:42)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflectFactory.cre
    te(EnhanceBeanReflectFactory.java:10)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanR
    flect(BeanDescriptorManager.java:1407)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createBy
    eCode(BeanDescriptorManager.java:1208)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDepl
    yAssociations(BeanDescriptorManager.java:1124)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEnti
    yDeploymentAssociations(BeanDescriptorManager.java:630)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(B
    anDescriptorManager.java:277)
    at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(Int
    rnalConfiguration.java:150)
    at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServe
    (DefaultServerFactory.java:209)
    at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServe
    (DefaultServerFactory.java:64)
    at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:78

    at org.bukkit.plugin.java.JavaPlugin.initialize(JavaPlugin.java:175)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.
    ava:138)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager
    java:158)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManage
    .java:106)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:84)
    at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:215)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:202)
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:142)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:257)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)
    Caused by: java.lang.NoSuchMethodException: com.vildaberper.Locker.Lock.<init>(

    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.defaultCon
    tructor(EnhanceBeanReflect.java:67)
    ... 21 more
    03:28:11 [ALLVARLIG] Could not load 'plugins\Locker.jar' in folder 'plugins':
    java.lang.RuntimeException: java.lang.NoSuchMethodException: com.vildaberper.Lo
    ker.Lock.<init>()
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.defaultCon
    tructor(EnhanceBeanReflect.java:69)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.<init>(Enh
    nceBeanReflect.java:42)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflectFactory.cre
    te(EnhanceBeanReflectFactory.java:10)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanR
    flect(BeanDescriptorManager.java:1407)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createBy
    eCode(BeanDescriptorManager.java:1208)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDepl
    yAssociations(BeanDescriptorManager.java:1124)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEnti
    yDeploymentAssociations(BeanDescriptorManager.java:630)
    at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(B
    anDescriptorManager.java:277)
    at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(Int
    rnalConfiguration.java:150)
    at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServe
    (DefaultServerFactory.java:209)
    at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServe
    (DefaultServerFactory.java:64)
    at com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:78

    at org.bukkit.plugin.java.JavaPlugin.initialize(JavaPlugin.java:175)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.
    ava:138)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager
    java:158)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManage
    .java:106)
    at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:84)
    at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:215)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:202)
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:142)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:257)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:375)
    Caused by: java.lang.NoSuchMethodException: com.vildaberper.Locker.Lock.<init>(

    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect.defaultCon
    tructor(EnhanceBeanReflect.java:67)
    ... 21 more


    Locker (Main)
    Lock
     
  14. Offline

    Mixcoatl

    Your Lock class is missing a default constructor. All persistent classes are required to have one.
     
  15. Offline

    vildaberper

    Thanks. works now! :D

    One question, is it possible to store Lists in the database?
    Because Im having troubles with that.
    No errors though, only thease on startup:
    Code:
    16:14:42 [INFO] DataSourcePool [Locker] autoCommit[false] transIsolation[SERIALI
    ZABLE] min[2] max[20]
    16:14:42 [INFO] SubClassFactory parent ClassLoader [org.bukkit.plugin.java.Plugi
    nClassLoader]
    
    Edit:
    oh, and one more thing.
    How can I clear the database?
     
  16. Offline

    Mixcoatl

    Woowoo!
    Yes, and no. The answer is complicated. First, the elements of the list need to be a persistent class, not Java primitive types. Secondly, the class that forms the elements of the list need to hold a reference to the object they're an element of.
    Here's how you would create a class that has a list field:
    Code:
    @Entity
    @Table(name="lister")
    class Lister {
        /*
         * OMITTING GETTERS AND SETTERS FOR BREVITY.
         */
        @OneToMany
        private List<Element> elements = new ArrayList<Element>();
        @Column(unique=true)
        @Id
        private Integer id;
    }
    And this is what the element class might look like:

    Code:
    @Entity
    @Table(name="lister_element")
    class Element {
        /*
         * OMITTING GETTERS AND SETTERS FOR BREVITY.
         */
        @ManyToOne
        @NotNull
        private Lister lister;
    
        @NotEmpty
        private String element;
    
        @Column(unique=true)
        @Id
        private Integer id;
    }
    These are normal. They just tell you what EBeans is doing.
    You have two options:
    • Write a plug-in command to delete the contents of your database tables.
    • Download and install an administration tool. For SQLite I recommend SQLiteAdmin. For MySQL you can use phpMyAdmin if you're system is running PHP. This is common on Linux systems. For PC or OSX systems I would recommend a tool called SQuirreL, although there are plenty of other good ones out there.
     
  17. Offline

    vildaberper

    Thanks!

    Nevermnd, I managed to clear the database.

    And thanks again! :D
     
  18. Offline

    Mixcoatl

    No problem!
    For what it's worth, it took me a little while to figure it out, myself. Deleting the DB file only worked until I had information in the database I wanted to keep. :eek:
     
Thread Status:
Not open for further replies.

Share This Page