[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I have a java program that is able to retrieve information from
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 7
Thread images: 1
File: n-tier-architecture.jpg (71 KB, 960x720) Image search: [Google]
n-tier-architecture.jpg
71 KB, 960x720
I have a java program that is able to retrieve information from a relational database and convert it into objects it can work with. I was told (at least I though I was) not to let the Model layer know about the ID's used in the database.

However, now that I'm trying to communicate the other way, I realize that this is impossible because I need the ID's when I try to update the database when I make changes to the objects.

I guess I could theoretically make a hashmap that links all objects to their database ID, but that seems like a memoryleak catastrophe waiting to happen.

Anyone have any experience with this n - tier database stuff?
>>
>>55157035
Why wouldn't you let the Model layer know about the IDs used in the database?

I'm not sure how your ORM works exactly. Does it not have any documentation on how to update records using the ORM's API? Wouldn't this also mean that you'd be writing update queries without even utilizing the ORM layer?

Read the docs, anon
>>
>>55157139
I've written the ORM myself.

>Why wouldn't you let the Model layer know about the IDs used in the database?
I'm beginning to heavily ask myself that same question. I think I might have misread something like "don't heavily rely on database ID's in your Model layer" as "don't use ID's in your Model at all"..

Although.. I guess using ID's in your model makes it a bit harder to switch to a completely different type of database.

Right now I'm doubting between use being a bit unkosher and using ID's anyway or using a map and dealing with a shitton of garbage collection, which you shouldn't really be doing in Java. Feels wrong either way.
>>
>>55157035
I usually don't rely on id's because there is usually one field that must remain constant, such as a username or something, so I end up just indexing that field, lookup, and then set the PUT record's id field to the one I found in the db and then upsert it.
>>
>>55157251
If your ORM can select rows from a database, then it can use the primary key column as the ID

Your ORM needs to be able to have access to IDs, otherwise how would you be able to query/retrieve records based on DB keys?
>>
>>55157035
Check the java persistence API. Once you understood it you won't have problems with I'D/updates.
But sill in this persistence api you need a ID in your classes
>>
>>55157299
>>55157305
>>55157336
kk got it, adding IDs to my model objects as we speak

Thanks for the input guys. Appreciate it.
Thread replies: 7
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.