简体   繁体   中英

Store session(data) into database

I am working with Java EE and I try to create a web application. I want to store the session data into the database.

The ways that I have considered are:

  1. Create tables to be able to store the data (I did not like this approach, because for every different web app we need to create different tables on database, and I think if you have complex session data this will be painful, to have all the relations etc.).

  2. Create Java class for holding the data, and store the JSON representation to the database. So when you retrieve the session data, you convert it back to Java object, with Jackson for instance.

  3. Store the serialized Java class object, and after deserialize it and use it.

I think that approach 2 and 3 is somehow more generic and don't need too much effort. Are these good approaches? Is there some other approaches better that that? What do you suggest me?

You should use Hibernate framework. It will automatically reduce lot of your work. Refer https://www.javatpoint.com/hibernate-tutorial .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM