tt1.setText(p.getId());
List<Integer> coolItemIds = new List<Integer>(); for(Item item : getItems()) { if(item.isCool()) { int itemId = item.getId(); coolItemIds.add(item); } }
/**Session starts***/ Item item = (Item) session.load(Item.class, new Long(1)); item.getId(); //Will not access DB as only the identifier property is access item.getDescription(); // access the DB and initialize the proxy . After that , the item proxy is said to be initialized item.getPrice(); //will not access DB as the item with the PK 1 can be get from the session Item item2 = session.get(Item.class, new Long(1)) //will not access DB as the item with the PK 1 can be get from the session
/** * @return the primary key assigned to this item */ public String getPrimaryKey() { return getId(); }
/** * @return the primary key assigned to this item */ public String getPrimaryKey() { return getId(); }
/** * @return the primary key assigned to this item */ public String getPrimaryKey() { return getId(); }
public boolean idValidate(int id) { for (Item i : items) if (i.getId() == id) return true; // stop as soon as one is true. return false; }
comboBox.setEditor(new ItemEditor()); class ItemEditor extends BasicComboBoxEditor { public void setItem(Object anObject) { Item item = (Item) anObject; editor.setText(item.getId() + ""); } }
/** * @return the primary key assigned to this item */ public String getPrimaryKey() { return getId(); }
int deleteId = s.nextInt(); Iterator<Item> it = items.iterator(); while (it.hasNext()) { Item next = it.next(); if (next.getId() == deleteId) { it.remove(); } }
ObjectMapper objectMapper = new ObjectMapper(); try { List<Item> items = objectMapper.readValue( yourJSONString, objectMapper.getTypeFactory().constructCollectionType(List.class, Item.class)); for (Item item : items) { System.out.println(item.getId()); } } catch (IOException e) { e.printStackTrace(); }
while(it.hasNext()) { Item item = (Item) it.next(); map.put( item.getId() , item.getContent() ) }
public Integer f() { Item item = new Item(); // this works: //return item == null ? new Integer(1) : item.getId(); // NPE?? return item == null ? 1 : item.getId(); }
String json = "[{id:1,label:2,code:3},{id:4,label:5,code:6}]"; List<Item> items = new Gson().fromJson(json, new TypeToken<List<Item>>(){}.getType()); List<List<String>> listOfLists = new ArrayList<>(); for (Item item : items) { List<String> subList = new ArrayList<>(); subList.add(item.getId()); subList.add(item.getLabel()); subList.add(item.getCode()); listOfLists.add(subList); } System.out.println(listOfLists); // [[1, 2, 3], [4, 5, 6]]
Session session = sessionFactory1.openSession(); Transaction tx = session.beginTransaction(); Item item = (Item) session.get(Item.class, new Long(1234)); tx.commit(); session.close(); // end of first session, item is detached item.getId(); // The database identity is "1234" item.setDescription("my new description"); Session session2 = sessionFactory.openSession(); Transaction tx2 = session2.beginTransaction(); Item item2 = (Item) session2.get(Item.class, new Long(1234)); Item item3 = session2.merge(item); // Success! tx2.commit(); session2.close();
Session session = sessionFactory1.openSession(); Transaction tx = session.beginTransaction(); Item item = (Item) session.get(Item.class, new Long(1234)); tx.commit(); session.close(); // end of first session, item is detached item.getId(); // The database identity is "1234" item.setDescription("my new description"); Session session2 = sessionFactory.openSession(); Transaction tx2 = session2.beginTransaction(); Item item2 = (Item) session2.get(Item.class, new Long(1234)); session2.update(item); // Throws NonUniqueObjectException tx2.commit(); session2.close();
List<Item> items = new ArrayList<Item>(); items.add(new Item()); String idToSearch = ID_SEARCHED; for(Item singleItem : items){ if(singleItem.getId().equals(ID_SEARCHED;)){ singleItem.setId(NEW_ID); } }
@Override public boolean equals (Object o) { if (!o instanceof Item) { return false; } Item other = (Item)o; return getId().equals(other.getId()) && getTitle().equals(other.getTitle()) && getDescription().equals(other.getDescription()); }
private HtmlInputHidden itemId = new HtmlInputHidden(); private Item item = new Item(); public void editItem() { // Action method when selecting an item for edit. itemId.setValue(item.getId()); } public void saveItem() { // Action method when saving edited item. item.setId((Integer) itemId.getValue()); }