I am using Entity bean in NetBeans, to develop some master/detail forms. When I run the forms, I click the Delete JButton, and the row dissapears from the JTable.
But when I click on "Reload", the supposedly deleted row shows up again. I don't know why is this happening; why does the Entity doesn't erase all the way to the database table, and just deletes it out of the JTable?
This sort of issue sounds like it's related to the separation of the data (the model) from the view. I don't have specific knowledge regarding your technologies used, but hopefully I can provide some insight into what is the root of your problem.
In your case, it sounds like when you "Delete" you're only removing it from the view; you're not actually manipulating the data in any way (i.e. the model is not aware of this deletion).
Therefore once you "Reload" - which usually means that the view asks the model for what data to present - your "deletion" is lost since the model hasn't changed at all, and thus provides the exact same data to the view.
This sort of behavior is likely to occur when you're manipulating the data (i.e. deleting things) via the JTree itself or even the contained TreeNode objects, rather than the underlying TreeModel.
Hopefully this information helps you, sorry I don't have a more specific answer.
The JTable when reloaded, brought the record deleted because it had a foreign key link and couldn't deleted it at database level.
Related
When changing the number of columns and rows of natTable
After clearing the column list of DataProvider, create a new column item and change the column item list of columnPropertyAccessor.
Then, put the new data model into the filter list and refresh it.
When the 7-column nattable is sorted (ascending or descending) and clicked, it is changed to a different data model (4 columns) as above, but if it is sorted, "CurrentModificationException" and "IndezxOutOfBoundException" occur.
If you exchange data models without sorting, there is no problem.
I don't know which part is causing it.
Is my way of replacing the filter list wrong when changing the data model?
If anyone has encountered a similar error and has solved it, please help.
Well you don't show how you are doing things, so I can't tell any details. But to answer your question, yes I think you are doing things wrong.
In short, if you have a state applied according to a column like sorting or filtering and you change the underlying data structure, things will break as the states does match the structure anymore. Not sure why you think this should work automatically.
If you change the underlying data structure you need to clear structure based states in advance.
There is an example in the NatTable examples application that shows how to change the data provider dynamically. Not sure if the example covers the clearing of states or if this is handled automatically when you are doing things correctly.
I'm currently sourcing some static data from a third party. It's a simple one-to-many, like this
garage:
id
name
desc
location
garage_price:
id
garage_id
price_type
price
Sometimes, the data is incorrect, and I will need to correct it. At the same time, I'd like to preserve the original sourced data somewhere and potentially run some queries to show the changes.
My question is whether someone is doing something like this with SQL, Java and Hibernate, and what's the approach you've taken, or would take.
I could add a boolean column, "original_data", to both tables, and before an update happens, run a trigger to copy the row from garage or garage_price into an "original_garage" or "original_price" table as long as original_data is true. Then set original_data to false, and all further updates will just happen on the garage/garage_price tables.
Anything wrong with that approach, and how do people typically work with multiple tables with the same data in Hibernate/JPA? Previously, I'd create a class that holds all the data, and subclass it twice, once per each table, while setting
#Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
on the parent.
As so often there are various options:
Use Hibernate Envers. It will keep a complete history of changes, so if you do multiple changes each will result in a row in the auditing tables. These tables are separate from your main data tables which might be a pro or a con, depending on your requirements.
Use the approach that you described: Write the original dataset, copy it before modifying it. You'll need two additional attributes:
A flag marking the original and a technical id do have a unique primary key.
Just as the second version, but you could actually do that in a trigger in the database. Which probably is faster, works no matter how the data gets inserted and to copy rows in the database is actually really easy, while it feels rather cumbersome in Java. Of course, writing triggers is considered a PITA in itself by many Java developers. If your application doesn't usually use triggers and stored procedures it is also really easy to forget about the trigger and being rather confused where these additional rows come from.
A user of my program ran into this issue with SWT's virtual tables: If one presses Ctrl+A and Ctrl+C in the table, not all elements will be copied to the clipboard, only the ones that have already been loaded.
This leads to a nasty surprise if the user relies on the false assumption that all table entries have been copied. Is there any reasonable (and if possible, unobtrusive) workaround to deal with this problem?
The SWT Table does not itself support copying its content, that must be part of the application ocde. Therefore I assume that you collect the text of the items (i.e. item.getText()) and then copy them to the clipboard.
To copy the entire contents of the table you would have to force all items to be materialized, for example by stepwise calling setTopIndex(), which will likely cause flicker.
I recommend to solve this on the model level. I.e. rewrite the copy code so that it uses the tables underlying data model to collect the necessary information.
My question in its simplest form: Is it possible to determine the subset of items (or the indices of the corresponding items) currently being displayed in a JavaFX TableView?
The reason I'm asking is that I want to implement lazy loading. Therefore, I subclass ObservableList and implement the code that fetches new items from the database in the overriden E get(int index) (using prefetch/cache). However, the entity objects might be changed by the user and are therefore observed by the database backend. That's why I'd like to detach them as soon as they are not displayed any more.
Many thanks in advance for any suggestions.
You can use VirtualFlow to get the indizes of the first and the last visible cell: Scroll TableView via a Button
However, as I understood it, this is more a hack then a real part of the API. Also you might run into trouble if you have more tables around, it will be triggered each time a table changes.
I'm learning Android by forking and modifying an open source app, FrontlineSMS for Android. Here's my copy!
I want to add a few tables, Poll and PollResponse, to the database, where Poll->PR is a one-to-many relationship.
I've added classes for Poll to the project. What is the "right" way to define the PollResponse object?
Saving the Poll data happens on line 562 of Keyword.java, and somehow in there a row is added to the database with a new ID created for that row. This is the place where I also want to save a few rows into PollResponse (which doesn't exist yet) and assign their id_poll field the value from the newly created Poll row. Is there a clean way to accomplish this child relationship, as some part of src/net/frontlinesms/android/model/Poll.java or /src/net/frontlinesms/android/model/PollDao.java? Or do I need to create completely separate PollResponse objects, save the data for the Poll, then query the database for the newly created ID and save that in PollResponses? The latter is the only way I can think to do it but it seems ugly. I also tried searching around for solutions to this but I may not have the right keywords in mind.
I discovered how to create a new table Poll by creating Poll.java and PollDao.java and adding the class to /src/net/frontlinesms/android/db/FrontlineSmsSqliteHelper.java , but I'm largely fumbling around this project, reading Android development guides and trial and error. Sorry for the lack of links, I'm only allowed 2 until I get more than 10 reputation. Thanks for your help!
*EDIT - Could there be a case for rewriting this project to use an ORM like greenDAO? Again I'm still learning Android so I'm not sure if the project uses any packaged ORM. It seems like it's custom written.