Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:33:31+00:00 2026-06-18T01:33:31+00:00

I have a class representing computer parts (specifically RAM modules) with properties in it,

  • 0

I have a class representing computer parts (specifically RAM modules) with properties in it, such as name, brand, price, and capacity. It needs to have a method to insert its own data into a database. I want it to insert all of its properties into the database, unless that property is null. Would the best way to do this to loop through a Map containing the String title of the column of the database and the method to obtain the corresponding property of the object? This is my first time using reflection, so if this is in fact the best way to do this, a snippet of sample code would be appreciated.

Thanks in advance,
Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:33:33+00:00Added an answer on June 18, 2026 at 1:33 am

    No. You are really talking more about a serialization problem than persistence. Persistence maintains the notion of entities, that have predefined properties, that are mapped to columns in the db. If you are just going to discover the properties, then you are basically serializing the object.

    The problem with doing that with reflection is that it will get really complicated when you start having graphs of objects that could contain cycles (objects that point back to nodes that have already been encountered).

    The other option is to just have a simple property mapping protocol, like Cocoa does: each object type knows how to encode itself, then decode itself, but from an encoder or decoder, which is format independent. So if you do it now in XML for 50 different entities then later want to support JSON you can without changing any of the entity code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class representing an object. It has 5 properties (a date,
I have a Person class which has a String collection of aliases representing additional
I have a datastore model representing items in an ecommerce site: class Item(db.Model): CSIN
I have a super-simple class representing a decimal # with fixed precision, and when
I have a C++ class representing a hierarchically organised data tree which is very
I have a Java class representing an event that contains some data, and also
I have created a custom JButton class for representing spaces on a monopoly board.
I have a class representing the current settings of the software that I'm developing
I have a static class representing a connection pool that I want to unit
I have a class that needs to have a variable of an unknown numeric

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.