OptimisticLockException

Discussion in 'Plugin Development' started by Staartvin, Feb 26, 2013.

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

    Staartvin

    Hello everyone,

    While I was testing out a self made plugin, I came across an error when I join my test server.
    This error has to do with ebeans. This is the error:

    http://pastebin.com/1UDBKktR

    NOTE: I have 2 events, PlayerJoinEvent and PlayerMoveEvent that access the database.

    My database class:

    Code:
    package me.staartvin.AntiAddict;
     
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
     
    import com.avaje.ebean.validation.NotNull;
     
    [USER=65976]Entity[/USER]()
    @Table(name = "AntiAddict_data")
    public class SqLiteDatabase {
     
        @Id
        private int id;
     
        @NotNull
        private int reputation;
     
        @NotNull
        private String playerName;
     
        @NotNull
        private String language;
     
        @NotNull
        private long joinTime;
     
        @NotNull
        private long joinTimeSave;
     
        @NotNull
        private long playTimeSave;
     
        @NotNull
        private long playTimeOld;
     
        @NotNull
        private long playTime;
     
        @NotNull
        private long playTimeInMinutes;
     
        @NotNull
        private long restTimeList;
     
        @NotNull
        private long restTime;
     
        @NotNull
        private long latestCheck;
     
        @NotNull
        private boolean playerBanned;
     
        @NotNull
        private long currentDate;
     
        @NotNull
        private long currentTime;
     
        @NotNull
        private boolean notDone;
     
        @NotNull
        private boolean warnMessage;
     
        public int getId() {
            return id;
        }
     
        public void setId(int id) {
            this.id = id;
        }
     
        public int getReputation() {
            return reputation;
        }
     
        public void setReputation(int reputation) {
            this.reputation = reputation;
        }
     
        public long getJoinTime() {
            return joinTime;
        }
     
        public void setJoinTime(long joinTime) {
            this.joinTime = joinTime;
        }
     
        public long getJoinTimeSave() {
            return joinTimeSave;
        }
     
        public void setJoinTimeSave(long joinTimeSave) {
            this.joinTimeSave = joinTimeSave;
        }
     
        public long getPlayTimeSave() {
            return playTimeSave;
        }
     
        public void setPlayTimeSave(long playTimeSave) {
            this.playTimeSave = playTimeSave;
        }
     
        public long getPlayTimeOld() {
            return playTimeOld;
        }
     
        public void setPlayTimeOld(long playTimeOld) {
            this.playTimeOld = playTimeOld;
        }
     
        public long getPlayTime() {
            return playTime;
        }
     
        public void setPlayTime(long playTime) {
            this.playTime = playTime;
        }
     
        public long getPlayTimeInMinutes() {
            return playTimeInMinutes;
        }
     
        public void setPlayTimeInMinutes(long playTimeInMinutes) {
            this.playTimeInMinutes = playTimeInMinutes;
        }
     
        public long getRestTimeList() {
            return restTimeList;
        }
     
        public void setRestTimeList(long restTimeList) {
            this.restTimeList = restTimeList;
        }
     
        public long getRestTime() {
            return restTime;
        }
     
        public void setRestTime(long restTime) {
            this.restTime = restTime;
        }
     
        public long getLatestCheck() {
            return latestCheck;
        }
     
        public void setLatestCheck(long latestCheck) {
            this.latestCheck = latestCheck;
        }
     
        public boolean isPlayerBanned() {
            return playerBanned;
        }
     
        public void setPlayerBanned(boolean playerBanned) {
            this.playerBanned = playerBanned;
        }
     
        public long getCurrentDate() {
            return currentDate;
        }
     
        public void setCurrentDate(long currentDate) {
            this.currentDate = currentDate;
        }
     
        public long getCurrentTime() {
            return currentTime;
        }
     
        public void setCurrentTime(long currentTime) {
            this.currentTime = currentTime;
        }
     
        public boolean isNotDone() {
            return notDone;
        }
     
        public void setNotDone(boolean notDone) {
            this.notDone = notDone;
        }
     
        public boolean isWarnMessage() {
            return warnMessage;
        }
     
        public void setWarnMessage(boolean warnMessage) {
            this.warnMessage = warnMessage;
        }
     
        public String getPlayerName() {
            return playerName;
        }
     
        public void setPlayerName(String playerName) {
            this.playerName = playerName;
        }
     
        public String getLanguage() {
            return language;
        }
     
        public void setLanguage(String language) {
            this.language = language;
        }
    }
    
    SetJoinTime Method:
    Code:
        protected void setJoinTime(String playerName, Long joinTime) {
            SqLiteDatabase entry = plugin.getDatabase().find(SqLiteDatabase.class).where()
                    .ieq("playerName", playerName).findUnique();
     
            if (entry == null)
                return;
     
            entry.setJoinTime(joinTime);
            plugin.getDatabase().save(entry);
        }
    Do you guys know what is going on?

    No one?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Pretty self-explainatory.
    You've changed something and the saved file isn't the same version as the load system, you can just delete it or revert the changes.
     
  3. Offline

    Staartvin

    I haven't changed anything. I haven't touched the database file either. That was the first thing I checked for.
     
  4. You should search on Google since this isn't Bukkit specific and you might just find the answer.
    I didn't use that db type myself so I can't help further.
     
  5. Offline

    Staartvin

    Hmm, ok. Thanks anyway.

    Is there anybody else who has a suggestion? I can't seem to find a solution on Google..

    Bump.

    Well, I still haven't fixed it and I need someone's advice. Is everyone dead?!

    It seems to error on:
    Code:
            plugin.dCon.setPlayTimeInMinutes(playerName,
                    plugin.dCon.getPlayTime(playerName) / 60000);
     
            plugin.dCon.setJoinTime(playerName, System.currentTimeMillis());
     
            plugin.dCon.setJoinTimeSave(playerName,
                    plugin.dCon.getJoinTime(playerName));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    jorisk322

    3 Bumps in one hour. Not sure if that's the solution to your problem.
     
  7. Offline

    Staartvin

    Nah, it's better than nothing. I'll stop and check tomorrow..
    It's just frustrating not getting it fixed..
     
  8. Offline

    Craftiii4

  9. Offline

    Milkywayz

    It's been stated you would have better answers elsewhere as this isn't really related to bukkit. Also ebean is not what most people use for databases, when I needed to use a mysql DB in one of my private plugins I borrowed and refitted the logblock DB classes for my own personal use. However you can't just steal their code and release it as your own plugin.
     
  10. Offline

    Staartvin

    Hmm, I'll see if I can contact the logblock team.
     
  11. Offline

    Milkywayz

    Their repository on github has the source your looking for, but again just skidding the code is not recommended. I only did so because it's a fully private plugin and didn't feel like writing my own mysql classes.
     
Thread Status:
Not open for further replies.

Share This Page