1
HashMap demoMap = new HashMap();
demoMap.put("1","Apple");
demoMap.put("1","Orange");
List<HashMap> demo = new ArrayList<HashMap>();
demo.add(demoMap);

Is it possible to store demo object in the db table. So that when I query table using jdbc or any orm I directly get the demo object.

SiddP
  • 1,603
  • 2
  • 14
  • 36
  • Yes, you can convert into ObjectStreams. By why would you go through that hassle. – Ashraff Ali Wahab Feb 10 '16 at 19:29
  • Why are you using a raw `HashMap` instead of a `Map`? – Louis Wasserman Feb 10 '16 at 19:29
  • Are you aware of run-time [`type erasure`](https://docs.oracle.com/javase/tutorial/java/generics/genTypes.html)? – PM 77-1 Feb 10 '16 at 19:33
  • @AshraffAliWahab and Louis . Its just an example. In a long shot I am using spring where I store objects in session objects which can hamper application performance so I wanted to know if it is possible to store collections directly in db so that I could store them in temporary tables. – SiddP Feb 10 '16 at 19:34
  • @PM77-1 No I am not. – SiddP Feb 10 '16 at 19:35

2 Answers2

1

If you want to store session info in the database, use JDBC session persistence

Which application server do you use? Here's a guide for Tomcat:

https://gerrydevstory.com/2013/08/21/tomcat-7-jdbc-session-persistence/

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • I am using tomcat . But when I use `connectionURL="jdbc:mysql://localhost/testing?user=root&password=root"` this I get `java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)` which is expected as the above connection dont have password but when I give it one `connectionURL="jdbc:mysql://localhost/testing?user=root&password=root"` I get error as `Could not load the Tomcat server configuration at \Servers\Tomcat v8.0 Server at localhost-config. The configuration may be corrupt or incomplete. The reference to entity "password" must end with the ';' delimiter.` – SiddP Feb 11 '16 at 05:28
0

Have a look over at this question and answer. Note that this will require you to modify your DDL, and it might not be appropriate for all situations. And, of course, it will only add specifically typed properties and not general objects (unless you use object serialization, but that would be an antipattern...)

Community
  • 1
  • 1
Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40