Solved EbeanServer Persistence Query List - returning non-specific object?

Discussion in 'Plugin Development' started by RROD, Apr 24, 2013.

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

    RROD

    Hi,

    I'm trying to work out what's going on here. It's my first time using javax.persistence.
    I've got a method which queries a database using EbeanServer. If you look into this you'll see an Object called "result", which is the result of the database query. The issue I'm facing is that when the EbeanServer is set to use MySQL, it works flawlessly. However when Ebean is using SQLite for it's database management the result is not an instanceof PlayerTable null. It most certainly shouldn't be. o.o
    How could this be? Is SQLite not available with Persistence? If so, what could I do about it?
    Really has baffled me with this one.

    Full class on GitHub

    Code:java
    1. /**
    2. * Load a player into the cache from the database.
    3. * @param player
    4. */
    5. public void loadPlayer(Player player) {
    6. if (isCached(player)) return;
    7. if (!databaseContains(player)) {
    8. BigBrother.debug("loadPlayer(): Generating a new database entry for " + player.getName());
    9. createPlayer(player, true);
    10. }
    11.  
    12. Query<?> q = database.find(BBTables.PLAYER_TABLE.getTable());
    13.  
    14. BigBrother.debug("loadPlayer(): Queried where player_name = " + player.getName() + " in 'bb_players'. ");
    15. q.where().eq("player_name", player.getName());
    16. q.setMaxRows(1);
    17.  
    18. if (q.findList() == null || q.findList().size() == 0) {
    19. BigBrother.debug("loadPlayer(): Query returned nothing! ");
    20. return;
    21. }
    22.  
    23. Object result = q.findList().get(0);
    24.  
    25. if (!(result instanceof PlayerTable)) {
    26. BigBrother.debug("The result is not an instanceof PlayerTable! ");
    27. BigBrother.debug("That's messed up even for my standards. ");
    28. return;
    29. }
    30. PlayerTable t = (PlayerTable)q.findList().get(0);
    31. player.setMetadata("bigbrother.watching", new FixedMetadataValue(plugin, t.getWatching()));
    32. }


    Okay, I'm pretty sure this issue stems a bit deeper than this. I'll give my code another look at today and see if there's a more efficient way of doing this.

    No luck :(
    I'm just going to have to exclude support for SQLite in the plugin until I can get this resolved.
    I don't plan on using anything other than Ebean.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. If you can't get EBeans stuff then why not use other lib for SQL ? It's not the only one you know.
    Search in the Resources section for SQL and you'll find alot of options.
     
  3. Offline

    RROD

    I am aware of that; I'll look around anyway.

    Now using PatPeter's library and writing my own SQL syntax.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    Ebeans does not work completely with the sqlite database. It's a known incompatibility in Ebeans itself. It does not handle foreign keys well for example.
     
Thread Status:
Not open for further replies.

Share This Page