Giter Club home page Giter Club logo

Comments (4)

noordawod avatar noordawod commented on August 25, 2024 1

Ahh, got it.

Unfortunately, the update() method is an all-in method so it will consider all columns. The only other solution is an updateBuilder(), something like this:

final UpdateBuilderUser, Long> builder = userDao.updateBuilder();
builder
  .updateColumnValue("address", "new address")
  .where().idEq(1);
builder.update();

Regarding the column names: yes, you should probably define constants for them, either alongside the main User.java class or inside it as an inner class.

Finally, you surely can consider an OAS3 specification which you can use just for the models.

from ormlite-jdbc.

noordawod avatar noordawod commented on August 25, 2024

Unsure what you really mean... Can you provide an example to showcase what you want?

from ormlite-jdbc.

dujianchi avatar dujianchi commented on August 25, 2024

I have code like this:

class User{
    Long id;
    String name;
    String password;
    String address;
}
....
Dao<User,Long> userDao = ....
....
User user = new User();
user.id=1;
user.name="test";
user.password="test";
user.address="test";
userDao.create(user);

and I want to update user's address where id=1, I want do this:

User user = new User();
user.id=1;
user.address="new address";
userDao.update(user);

and then, it throw exception that some column can not be null.
I know it hava UpdateBuilder, but UpdateBuilder need column name, and I don't think update method should care column name when I already have a POJO.

from ormlite-jdbc.

j256 avatar j256 commented on August 25, 2024

Another way to do this is to get the user from the database and then update it.

User user = userDao.queryForId(1);
user.address = "new address";
userDao.update(user);

That's how it is supposed to work. Or, as @noordawod said, you should use the UpdateBuilder.

from ormlite-jdbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.